linux cat命令詳解

來源:互聯網
上載者:User

linux cat 命令詳解,在講解該命令以前,先來看一下這個命令兩個執行個體,通過執行個體我們在來看cat的詳細參數,該命令主要是對文檔內容進行添加,
範例:
把 textfile1 的檔案內容加上行號後輸入 textfile2 這個檔案裡
cat -n textfile1 > textfile2
把 textfile1 和 textfile2 的檔案內容加上行號(空白行不加)之後將內容附加到 textfile3 裡。
cat -b textfile1 textfile2 >> textfile3
cat /dev/null > /etc/test.txt 此為清空/etc/test.txt檔案內容
cat 也可以用來製作 image file。例如要製作軟碟的 image file,將軟碟放好後打
cat /dev/fd0 > OUTFILE
相反的,如果想把 image file 寫到軟碟,請打
cat IMG_FILE > /dev/fd0

使用許可權:所有使用者
使用方式:cat [-AbeEnstTuv] [--help] [--version] fileName
說明:把檔案串聯接後傳到基本輸出(螢幕或加 > fileName 到另一個檔案)
參數:
-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 裡。

註:
1. OUTFILE 指輸出的 image 檔名。
2. IMG_FILE 指 image file。
3. 若從 image file 寫回 device 時,device 容量需與相當。
4. 通常用在製作開機磁片。



作者 feihan21

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.