[筆記] The Linux Command Line: A complete Introduction 指令大全心得 – 5

The Linux Command Line: A complete Introduction 放在桌上許久,於是想說利用 ChatGPT 4 來當指導員,協助自己熟悉上手。這篇筆記下第六個 Chapter – 重新導向。

notes-the-linux-command-line-a-complete-introduction-1


內容

指令

1. cat – 合併文件
2. sort – 排序文字行
3. uniq – 回報或是忽略重複的行
4. grep – 列出符合比對結果的行
5. wc – 列出符合比對結果的行
6. head – 輸出檔案的頁首
7. tail – 輸出檔案的頁尾
8. tee – 從標準輸入讀取後,再寫入到標準輸出和檔案。
像是:ls /usr/bin | tee -a ls.txt | grep zip
這將會保留 ls.txt 中原有的內容,並將新的輸出追加到文件末尾

stdin, stdout, stderr

stdin – standard input, 標準輸出, 描述符是 1
stdout – standard output, 標準輸出, 描述符是 0
stderr – standard error, 標準錯誤, 描述符是 2

使用的指令,會依據情境而內建產生標準輸出 (如到螢幕)或是產生錯誤。程式也會利用 stdin 來獲取輸入訊息,一般而言會是指鍵盤。我們可以透過指令來改變標準輸出、標準錯誤,使其存到一個檔案中。

運算子

1. > – rewrite 將標準輸出,覆寫寫入到一個檔案中,原有的內容會消失。請小心使用。
2. >> – append 添加到原有標準輸出的內容之後
3. &> – 同時將標準輸出和標準錯誤,覆寫寫入到一個檔案中,原有的內容會消失
4. &>> – 同時將標準輸出和標準錯誤,添加寫入到一個檔案原有內容後
5. | – 代表管線的連續操作,照順序執行


ChatGPT 對話

https://chat.openai.com/share/9f873018-7e4a-4649-950b-76c21d51934f


相關文章

按讚加入粉絲團

延伸閱讀