1.cat命令功能
cat命令的用途是連接文件或標準輸入並打印。這個命令常用來顯示文件內容,或者將幾個文件連接起來顯示,或者從標準輸入讀取內容並顯示,它常與重定向符號配合使用
2.cat命令格式
cat [option]... [file]...
3.cat命令參數
-A, --show-all 等價於 -vET -b, --number-nonblank 對非空輸出行編號 -e 等價於 -vE -E, --show-ends 在每行結束處顯示 $ -n, --number 對輸出的所有行編號 -s, --squeeze-blank 不輸出多行空行 -t 與 -vT 等價 -T, --show-tabs 將跳格字符顯示爲 ^I -u (被忽略) -v, --show-nonprinting 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外 --help 顯示此幫助信息並離開
4.cat命令實例
a.查看文件內容
#cat 文件名 [root@centos-5 ~]# cat demo.txt aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccc dddddddddddddddddddd #cat -n 文件名 顯示內容行號 [root@centos-5 ~]# cat -n demo.txt 1 aaaaaaaaaaaaaaaaaaaa 2 bbbbbbbbbbbbbbbbbbbb 3 ccccccccccccccccccccc 4 dddddddddddddddddddd [root@centos-5 ~]# cat -ne demo.txt 1 aaaaaaaaaaaaaaaaaaaa$ 2 bbbbbbbbbbbbbbbbbbbb$ 3 ccccccccccccccccccccc$ 4 dddddddddddddddddddd$
b.cat 創建文件並追加內容,也可以向已有文件追加內容
[root@centos-5 ~]# cat > text.txt aaaaaaaa vvvvvvvv [root@centos-5 ~]# ll total 96 drwxr-xr-x 2 root root 4096 Dec 6 00:40 aaaa -rw------- 1 root root 909 Mar 8 2016 anaconda-ks.cfg -rw-r--r-- 1 root root 5 Dec 9 01:25 a.txt -rw-r--r-- 1 root root 85 Dec 9 01:08 demo.txt -rw-r--r-- 1 root root 81 Jan 12 2010 index.html -rw-r--r-- 1 root root 36494 Mar 8 2016 install.log -rw-r--r-- 1 root root 3849 Mar 8 2016 install.log.syslog -rw-r--r-- 1 root root 18 Dec 9 01:27 text.txt [root@centos-5 ~]# cat >> B.txt <<EOF > aaaaaaaaaaaaaaaaa > bbbbbbbbbbbbbbbbbbb > ccccccccccccccccc > EOF [root@centos-5 ~]# LL -bash: LL: command not found [root@centos-5 ~]# ll total 104 drwxr-xr-x 2 root root 4096 Dec 6 00:40 aaaa -rw------- 1 root root 909 Mar 8 2016 anaconda-ks.cfg -rw-r--r-- 1 root root 5 Dec 9 01:25 a.txt -rw-r--r-- 1 root root 56 Dec 9 01:30 B.txt -rw-r--r-- 1 root root 85 Dec 9 01:08 demo.txt -rw-r--r-- 1 root root 81 Jan 12 2010 index.html -rw-r--r-- 1 root root 36494 Mar 8 2016 install.log -rw-r--r-- 1 root root 3849 Mar 8 2016 install.log.syslog -rw-r--r-- 1 root root 18 Dec 9 01:27 text.txt
c.cat 連接多個文件的內容並且輸出到一個新文件中
[root@centos-5 ~]# cat a.txt aaaa [root@centos-5 ~]# cat B.txt aaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbb ccccccccccccccccc [root@centos-5 ~]# cat demo.txt aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccc dddddddddddddddddddd [root@centos-5 ~]# cat a.txt B.txt >> demo.txt [root@centos-5 ~]# cat demo.txt aaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccc dddddddddddddddddddd aaaa aaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbb ccccccccccccccccc