六月丁香五月婷婷,丁香五月婷婷网,欧美激情网站,日本护士xxxx,禁止18岁天天操夜夜操,18岁禁止1000免费,国产福利无码一区色费

學(xué)習(xí)啦>學(xué)習(xí)電腦>操作系統(tǒng)>Linux教程>

linux的cat命令的詳細(xì)解釋

時間: 佳洲1085 分享

  linux下的cat是一個文本文件查看和連接工具,它主要是用來查看文件內(nèi)容的。下面由學(xué)習(xí)啦小編整理了linux的cat命令的詳細(xì)解釋,希望對你有幫助。

  linux的cat命令的詳細(xì)解釋

  cat 是一個文本文件查看和連接工具。查看一個文件的內(nèi)容,用cat比較簡單,就是cat 后面直接接文件名。

  比如:

  de>[root@localhost ~]# cat /etc/fstabde>

  為了便于新手弟兄靈活掌握這個工具,我們多說一點常用的參數(shù);

  1、linux的cat命令語法結(jié)構(gòu)

  de>cat [選項] [文件]...de>

  選項-A, --show-all 等價于 -vET-b, --number-nonblank 對非空輸出行編號-e 等價于 -vE-E, --show-ends 在每行結(jié)束處顯示 $-n, --number 對輸出的所有行編號-s, --squeeze-blank 不輸出多行空行-t 與 -vT 等價-T, --show-tabs 將跳 字符顯示為 ^I-u (被忽略)-v, --show-nonprinting 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外--help 顯示此幫助信息并離開

  2、linux的cat命令的詳解實例

  實例一、查看文件內(nèi)容

  de>[root@localhost ~]# cat /etc/profile 注:查看/etc/目錄下的profile文件內(nèi)容;

  [root@localhost ~]# cat -b /etc/fstab 注:查看/etc/目錄下的profile內(nèi)容,并且對非空白行進(jìn)行編號,行號從1開始;

  [root@localhost ~]# cat -n /etc/profile 注:對/etc目錄中的profile的所有的行(包括空白行)進(jìn)行編號輸出顯示;

  [root@localhost ~]# cat -E /etc/profile 注:查看/etc/下的profile內(nèi)容,并且在每行的結(jié)尾處附加$符號;de>

  cat 加參數(shù)-n 和nl工具差不多,文件內(nèi)容輸出的同時,都會在每行前面加上行號;

  de>[root@localhost ~]# cat -n /etc/profile

  [root@localhost ~]# nl /etc/profilede>

  cat 可以同時顯示多個文件的內(nèi)容,比如我們可以在一個cat命令上同時顯示兩個文件的內(nèi)容;

  de>[root@localhost ~]# cat /etc/fstab /etc/profilede>

  cat 對于內(nèi)容極大的文件來說,可以通過管道|傳送到more 工具,然后一頁一頁的查看;

  de>[root@localhost ~]# cat /etc/fstab /etc/profile | morede>

  實例二、cat 的創(chuàng)建、連接文件功能實例;

  cat 有創(chuàng)建文件的功能,創(chuàng)建文件后,要以EOF或STOP結(jié)束;

  de>[root@localhost ~]# cat > linuxsir.org.txt << EOF 注:創(chuàng)建linuxsir.org.txt文件;

  > 我來測試 cat 創(chuàng)建文件,并且為文件輸入內(nèi)容; 注:這是為linuxsir.org.txt文件輸入內(nèi)容;

  > 北南南北 測試; 注:這是為linuxsir.org.txt文件輸入內(nèi)容;

  > EOF 注:退出編輯狀態(tài);

  [root@localhost ~]# cat linuxsir.org.txt 注:我們查看一下linuxsir.org.txt文件的內(nèi)容;

  我來測試 cat 創(chuàng)建文件,并且為文件輸入內(nèi)容;

  北南南北 測試;de>

  cat 還有向已存在的文件追加內(nèi)容的功能;

  de>[root@localhost ~]# cat linuxsir.txt 注:查看已存在的文件linuxsir.txt 內(nèi)容;

  I am BeiNanNanBei From LinuxSir.Org . 注:內(nèi)容行

  我正在為cat命令寫文檔

  [root@localhost ~]# cat >> linuxsir.txt << EOF 注:我們向linuxsir.txt文件追加內(nèi)容;

  > 我來測試cat向文檔追加內(nèi)容的功能; 注:這是追回的內(nèi)容

  > OK?

  > OK~

  > 北南 呈上

  > EOF 注:以EOF退出;

  [root@localhost ~]# cat linuxsir.txt 注:查看文件內(nèi)容,看是否追回成功。

  I am BeiNanNanBei From LinuxSir.Org .

  我正在為cat命令寫文檔

  我來測試cat向文檔追加內(nèi)容的功能;

  OK?

  OK~

  北南 呈上de>

  cat 連接多個文件的內(nèi)容并且輸出到一個新文件中;

  假設(shè)我們有sir01.txt、sir02.tx和sir03.txt ,并且內(nèi)容如下;

  de>[root@localhost ~]# cat sir01.txt

  123456

  i am testing

  [root@localhost ~]# cat sir02.txt

  56789

  BeiNan Tested

  [root@localhost ~]# cat sir03.txt

  09876

  linuxsir.org testingde>

  我想通過cat 把sir01.txt、sir02.txt及sir03.txt 三個文件連接在一起(也就是說把這三個文件的內(nèi)容都接在一起)并輸出到一個新的文件sir04.txt 中。

  注意:其原理是把三個文件的內(nèi)容連接起來,然后創(chuàng)建sir04.txt文件,并且把幾個文件的內(nèi)容同時寫入sir04.txt中。特別值得一提的是,如果您輸入到一個已經(jīng)存在的sir04.txt 文件,會把sir04.txt內(nèi)容清空。

  de>[root@localhost ~]# cat sir01.txt sir02.txt sir03.txt > sir04.txt

  [root@localhost ~]# more sir04.txt

  123456

  i am testing

  56789

  BeiNan Tested

  09876

  linuxsir.org testingde>

  cat 把一個或多個已存在的文件內(nèi)容,追加到一個已存在的文件中

  de>[root@localhost ~]# cat sir00.txt

  linuxsir.org forever

  [root@localhost ~]# cat sir01.txt sir02.txt sir03.txt >> sir00.txt

  [root@localhost ~]# cat sir00.txt

  linuxsir.org forever

  123456

  i am testing

  56789

  BeiNan Tested

  09876

  linuxsir.org testingde>

3634900