Linux — cat 命令的使用方法

來源:互聯網
上載者:User
 cat 主要有三大功能:

 

1. 一次顯示整個檔案

cat filename

2. 從鍵盤建立一個檔案

cat > filename

只能建立新檔案,不能編輯已有檔案。

3. 將幾個檔案合并為一個檔案

cat file1 file2 > file

 

cat 具體命令格式為:

 

cat [-AbeEnstTuv] [--help] [--version] fileName

 

說明:把檔案串聯接後傳到基本輸出(螢幕 & "> fileName" 到另一個檔案)
參數:
  -n 或 –number 由 1 開始對所有輸出的行數編號
  -b 或 –number-nonblank 和 -n 相似,只不過對於空白行不編號
  -s 或 –squeeze-blank 當遇到有連續兩行以上的空白行,就代換為一行的空白行
  -v 或 –show-nonprinting

 

範例:

 

* 把 linuxfile1 的檔案內容加上行號後輸入 linuxfile2 這個檔案裡:

cat -n linuxfile1 > linuxfile2

* 把 linuxfile1 和 linuxfile2 的檔案內容加上行號(空白行不加)之後將內容附加到linuxfile3 裡: 

cat -b linuxfile1 linuxfile2 > linuxfile3

* 清空/etc/test.txt檔案內容

cat /dev/null > /etc/test.txt

 

參考:http://www.9usb.net/200902/linux-cat.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.