精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學(xué)習(xí)啦>學(xué)習(xí)電腦>操作系統(tǒng)>Linux教程>

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

      時(shí)間: 佳洲1085 分享

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

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

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

        比如:

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

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

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

        de>cat [選項(xiàng)] [文件]...de>

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

        2、linux的cat命令的詳解實(shí)例

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        北南南北 測(cè)試;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)容;

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

        > OK?

        > OK~

        > 北南 呈上

        > EOF 注:以EOF退出;

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

        I am BeiNanNanBei From LinuxSir.Org .

        我正在為cat命令寫文檔

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

        OK?

        OK~

        北南 呈上de>

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

        假設(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>

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

        注意:其原理是把三個(gè)文件的內(nèi)容連接起來(lái),然后創(chuàng)建sir04.txt文件,并且把幾個(gè)文件的內(nèi)容同時(shí)寫入sir04.txt中。特別值得一提的是,如果您輸入到一個(gè)已經(jīng)存在的sir04.txt 文件,會(huì)把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 把一個(gè)或多個(gè)已存在的文件內(nèi)容,追加到一個(gè)已存在的文件中

        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