Showing posts with label دستور Cat. Show all posts
Showing posts with label دستور Cat. Show all posts

Sunday, March 17, 2013

Easy learn linux command line- Part 16

hello again, you learned how to use command line for open files in terminal in the last post. now you need to edit files!

what is your recommendation comment?
if you don't have any idea, this post is especially write for you. only persons that need to edit, compare two files with together,found differences between files, merging them, found any word and replace in the files, remove empty rows, sort content and etc.

Command Description
# cat example.txt | awk 'NR%2==1' remove all even lines from example.txt   
# echo a b c | awk '{print $1}' view the first column of a line   
# echo a b c | awk '{print $1,$3}' view the first and third column of a line   
# cat -n file1 number row of a file   
# comm -1 file1 file2 compare contents of two files by deleting only unique lines from 'file1'   
# comm -2 file1 file2 compare contents of two files by deleting only unique lines from 'file2'   
# comm -3 file1 file2 compare contents of two files by deleting only the lines that appear on both files   
# diff file1 file2 find differences between two files   
# grep Aug /var/log/messages look up words "Aug" on file '/var/log/messages'   
# grep ^Aug /var/log/messages look up words that begin with "Aug" on file '/var/log/messages'   
# grep [0-9] /var/log/messages select from file '/var/log/messages' all lines that contain numbers   
# grep Aug -R /var/log/* search string "Aug" at directory '/var/log' and below   
# paste file1 file2 merging contents of two files for columns   
# paste -d '+' file1 file2 merging contents of two files for columns with '+' delimiter on the center   
# sdiff file1 file2 find differences between two files and merge interactively alike "diff"   
# sed 's/string1/string2/g' example.txt replace "string1" with "string2" in example.txt   
# sed '/^$/d' example.txt remove all blank lines from example.txt   
# sed '/ *#/d; /^$/d' example.txt remove comments and blank lines from example.txt   
# sed -e '1d' exampe.txt eliminates the first line from file example.txt   
# sed -n '/string1/p' view only lines that contain the word "string1"   
# sed -e 's/ *$//' example.txt remove empty characters at the end of each row   
# sed -e 's/string1//g' example.txt remove only the word "string1" from text and leave intact all   
# sed -n '1,5p' example.txt print from 1th to 5th row of example.txt   
# sed -n '5p;5q' example.txt print row number 5 of example.txt   
# sed -e 's/00*/0/g' example.txt replace more zeros with a single zero   
# sort file1 file2 sort contents of two files   
# sort file1 file2 | uniq sort contents of two files omitting lines repeated   
# sort file1 file2 | uniq -u sort contents of two files by viewing only unique line   
# sort file1 file2 | uniq -d sort contents of two files by viewing only duplicate line   
# echo 'word' | tr '[:lower:]' '[:upper:]' convert from lower case in upper case   

Tuesday, February 26, 2013

آموزش خط فرمان-قسمت پانزدهم

حتما این جمله را بارها شنیده اید که در لینوکس هر چیزی به صورت فایل متنی است، همین ویژگی جالب لینوکس سبب شده است که کاربران آن بتوانند به راحتی نسبت به مطالعه اطلاعات سیستمی و تغییر آنها اقدام نمایند.از فایل های کاربران گرفته تا ریز اطلاعات سخت افزارهایی همچون پردازنده، کارت گرافیکی و ... در لینوکس به صورت فایل ذخیره می شود.
ممکن گهگاهی نیازمند باشید این فایل ها را به هر دلیلی ملاحظه نموده و تغییر دهید. به همین دلیل و با توجه به اجازه های دسترسی به این فایل ها نیازمند استفاده از خط فرمان جهت بازکردن و اعمال تغییرات خواهید بود. در قسمت پانزدهم اموزش خط فرمان لینوکس می آموزیم چگونه یک فایل را بازنموده و محتویات آنرا ببینیم.



مشاهده ی محتویات فایل

دستور توضیح
# cat file1 نمایش محتویات یک فایل با شروع از سطر اول   
# head -2 file1 نمایش دو خط اول یک فایل   
# less file1 مشابه دستور more است با این تفاوت که امکان حرکت رو به عقب نیز وجود دارد   
# more file1 نمایش محتویات یک فایل به صورت درصدی و رو به جلو   
# tac file1 نمایش محتویات یک فایل با شروع از خط آخر   
# tail -2 file1 نمایش دو خط آخر یک فایل   
# tail -f /var/log/messages نمایش محتویات یک فایل به طوری که تغییرات صورت گرفته در فایل به طور لحظه ای نمایش داده می شود