以is為例,全稱為list。螢幕也是一個檔案。
第六章 Redirection 重新導向
● cat - Concatenate files 連結文件
cat 命令讀取一個或多個文件,然後復制它們到標準輸出
● sort - Sort lines of text 排序文字檔案的列
幫我們進行排序,而且可以依據不同的資料型態來排序
● uniq - Report or omit repeated lines 報導或省略重複列
排序完成了,想要將重複的資料僅列出一個顯示
● grep - Print lines matching a pattern 列出一樣、符合的列
● wc - Print newline, word, and byte counts for each file 列印檔案中分行符號,字,和位元組個數
想知道這個檔案裡面有多少字?多少行?多少字元,可以利用 wc 這個指令來達成
● head - Output the first part of a file 輸出文件第一部分
顯示出一個檔案的前幾行
● tail - Output the last part of a file 輸出文件最後一部分
顯示的是後面幾行
● tee - Read from standard input and write to standard output and files 從Stdin讀取資料,並同時輸出到Stdout和檔案
Standard Input, Output, And Error 標準輸入,輸出,和錯誤
執行程式程序,會得到兩種結果:
1First, we have the program's results; that is, the data the program is designed to produce
第一,程序運行結果;這是說,程序要完成的功能。
2 we have status and error messages that tell us how the program is getting along.
第二,我們得到狀態和錯誤信息, 這些告訴我們程序進展。
stdin 標準輸入
stdout 標準輸出
stderr 標準錯誤
✦預設情況下,標準輸出和標準錯誤都連接到屏幕
✦預設情況下, 標準輸入連接到鍵盤。
[me@linuxbox ~]$ ls -l /usr/bin > ls-output.txt
-把ls 命令的運行結果輸送到文件ls-output.txt 中去, 由文件代替屏幕。創建了一個長長的目錄/usr/bin 列表,並且輸送程序運行結果到文件ls-output.txt 中。
[me@linuxbox ~]$ ls -l /bin/usr > ls-output.txt
ls: cannot access /bin/usr: No such file or directory
-收到一個錯誤信息。指定了一個不存在的目錄/bin/usr, 但是為什麼這條錯誤信息顯示在屏幕上而不是被重定向到文件ls-output.txt?答案是, ls 程序不把它的錯誤信息輸送到標準輸出。反而,ls 把錯誤信息送到標準錯誤。而我們只是重定向了標準輸出,而沒有重定向標準錯誤, 所以錯誤信息被送到屏幕。標準輸出0,標準輸入1,標準錯誤2
[me@linuxbox ~]$ ls -l /bin/usr 2> ls-error.txt
多了一個2,其稱之為檔案描述語(詞),0,1,2分別為stdin,stdout ,stderr
重定向標準輸出和錯誤到同一個文件
[me@linuxbox ~]$ ls -l /bin/usr > ls-output.txt 2>&1
[me@linuxbox ~]$ ls -l /bin/usr &> ls-output.txt
ls -l /bin/usr &> ls-output.txt一個箭頭為新增ls -l /bin/usr &>> ls-output.txt兩個箭頭為appended
cat – Concatenate Files
後面的參數可以是多個檔案,less後面只能有一個。cat並且能將檔案合為一個檔案。
若只輸入cat,不會有任何反應,但只要輸入任何文字,其將會顯示一模一樣的文字。
而ctrl +d告訴它已經輸入完畢。
command1 > file1 箭頭為送給檔案
command1 | command2面對檔案
sort為排序
unig為唯一
uniq通常會跟sort一起出現 ,意思是把重複者刪除
wc – Print Line, Word, And Byte Counts有幾行幾個自己的byte
grep – Print Lines Matching A Pattern去檔案之中去抓取符合檔案格式之檔案
ls /bin /usr/bin | sort | uniq | grep zip-i忽略大小寫
ls /bin /usr/bin | sort | uniq | grep zip-v不要zip這三個字母的檔案
tee – Read From Stdin And Output To Stdout And Files 從stdin讀取檔案,在輸出存取到檔案中。
沒有留言:
張貼留言