歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux cat命令用法

Linux cat命令用法

日期:2017/2/28 15:29:15   编辑:Linux教程

Linux Cat命令主要有三大功能:

1.Linux Cat命令一次顯示整個文件。$ cat filename

2.Linux Cat命令從鍵盤創建一個文件。$ cat > filename(只能創建新文件,不能編輯已有文件.)

3.Linux Cat命令將幾個文件合並為一個文件。$cat file1 file2 > file

參數:

-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 裡。

范例:

cat -n textfile1 > textfile2 把 textfile1 的檔案內容加上行號後輸入 textfile2 這個檔案裡

cat -b textfile1 textfile2 >> textfile3 把 textfile1 和 textfile2的檔案內容加上行號(空白行不加)之後將內容附加到 textfile3裡。

cat /dev/null > /etc/test.txt 此為清空/etc/test.txt檔案內容

cat 也可以用來制作 image file。

cat /dev/fd0 > OUTFILE 例如要制作軟碟的 image file,將軟碟放好後打

cat IMG_FILE > /dev/fd0 相反的,如果想把 image file 寫到軟碟,請打

注:

1. OUTFILE 指輸出的 image 檔名。

2. IMG_FILE 指 image file。

3. 若從 image file 寫回 device 時,device 容量需與相當。

4. 通常用在制作開機磁片。

Copyright © Linux教程網 All Rights Reserved