cat 把檔案串連接后傳到標準輸出
參數:
-n 或 --number 由 1 開始對所有輸出的行數編號
-b 或 --number-nonblank 和 -n 相似,只不過對于空白行不編號
-s 或 --squeeze-blank 當遇到有連續兩行以上的空白行,就代換為一行的空白行
-v 或 --show-nonprinting
范例:
cat -n textfile1 > textfile2 把 textfile1 的檔案內容加上行號后輸入 textfile2 這個檔案里
cat -b textfile1 textfile2 >> textfile3 把 textfile1 和 textfile2 的檔案內容加上行號(空白行不加)之后將內容附加到 textfile3 里。
范例:
把 textfile1 的檔案內容加上行號后輸入 textfile2 這個檔案里
cat -n textfile1 > textfile2
把 textfile1 和 textfile2 的檔案內容加上行號(空白行不加)之后將內容附加到 textfile3 里。
cat -b textfile1 textfile2 >> textfile3
cat /dev/null > /etc/test.txt 此為清空/etc/test.txt檔案內容
如果在命令行中直接輸入cat,那么接下來,你輸入什么,會立即顯示什么,直到ctrl+D結束文件輸入
cat > junk