Linux命令之cat

來源:互聯網
上載者:User

cat

命令說明:
 
查看檔案內容,也可以給檔案追加內容到結尾
 
文法:
 
cat [-AbEnTv]
 
參數:
 
-A :相當於-vET的整合參數,可以列出一些特殊字元,而不是空白而已
 
-b :列出行號,僅對非空行號顯示,空白行不標記行號
 
-E :將結尾的斷行字元$顯示出來
 
-n :列印出行號,連同空白行也有行號,與-b參數不同
 
-T :將[tab]按鍵以^I 顯示出來
 
-v :列出一些看不出的特殊字元
 
 
 
cat主要有三大功能:
 
1.一次顯示整個檔案。$ cat  filename
 
2.從鍵盤建立一個檔案。$ cat  >  filename
 
        只能建立新檔案,不能編輯已有檔案
 
3.將幾個檔案合并為一個檔案。 $cat  file1  file2  > file
 
 
 
cat >>oldboy.txt<<EOF    #EOF為開始和結束的標籤,可用其他標籤替換
 
I am studing linux     

EOF        #EOF必須在行首,輸入完成後按[Enter]即可
 
 
 
命令實踐:
 


[root@ www.bkjia.com~]# cat /etc/issue
 
CentOS release 5.5 (Final)
 
Kernel \r on an \m

[root@ www.bkjia.com~]# cat -n /etc/issue
 
    1  CentOS release 5.5 (Final)
 
    2  Kernel \r on an \m
 
    3                              -n參數空白行也標記行號
 
[root@ www.bkjia.com~]# cat -b /etc/issue

    1  CentOS release 5.5 (Final)
 
    2  Kernel \r on an \m            -b參數空白行沒有行號
 
 
 
[root@yubing ~]# touch yubing.txt
 
[root@yubing ~]# cat >>yubing.txt<<END      追加內容
 
> my name is yubing
 
> END
 
[root@yubing ~]# cat yubing.txt
 
my name is yubing
 
[root@yubing ~]#
 
 
 
[root@yubing ~]# cat >yubing.txt  注意 > 符號
 
hi my name is yubing,
 
                        此處ctrl+c結束跳出
 
[root@yubing ~]# ll
 
total 80
 
-rw------- 1 root root  887 Apr  7 01:47 anaconda-ks.cfg
 
-rw-r--r-- 2 root root  255 Jan  6  2007 crontab1
 
lrwxrwxrwx 1 root root    12 Apr  8 04:06 crontab2 -> /etc/crontab
 
-rw-r--r-- 1 root root 23947 Apr  7 01:47 install.log
 
-rw-r--r-- 1 root root  3619 Apr  7 01:46 install.log.syslog
 
drwxr-xr-x 7 root root  4096 Oct 28  2011 oldboy
 
-rw-r--r-- 1 root root  425 Apr 14 14:13 oldboy.tar.gz
 
-rw-r--r-- 1 root root    22 Apr 17 01:26 yubing.txt
 
 [root@yubing ~]# cat >yubing.txt1
 
i love you
 
 [root@yubing ~]# ll
 
total 88
 
-rw------- 1 root root  887 Apr  7 01:47 anaconda-ks.cfg
 
-rw-r--r-- 2 root root  255 Jan  6  2007 crontab1
 
lrwxrwxrwx 1 root root    12 Apr  8 04:06 crontab2 -> /etc/crontab
 
-rw-r--r-- 1 root root 23947 Apr  7 01:47 install.log
 
-rw-r--r-- 1 root root  3619 Apr  7 01:46 install.log.syslog
 
drwxr-xr-x 7 root root  4096 Oct 28  2011 oldboy
 
-rw-r--r-- 1 root root  425 Apr 14 14:13 oldboy.tar.gz
 
-rw-r--r-- 1 root root    21 Apr 17 01:30 yubing.txt
 
-rw-r--r-- 1 root root    11 Apr 17 01:31 yubing.txt1
 
[root@yubing ~]# cat yubing.txt yubing.txt1>yubing.txt2 將兩個檔案合并成一個檔案
 
[root@yubing ~]# cat yubing.txt2
 
hi my name is yubing
 
i love you                    兩個檔案的內容都會顯示
 
[root@yubing ~]#

聯繫我們

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