歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux命令之cat

Linux命令之cat

日期:2017/2/28 14:49:23   编辑:Linux教程

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.linuxidc.com~]# cat /etc/issue

CentOS release 5.5 (Final)

Kernel \r on an \m

[root@ www.linuxidc.com~]# cat -n /etc/issue

1 CentOS release 5.5 (Final)

2 Kernel \r on an \m

3 -n參數空白行也標記行號

[root@ www.linuxidc.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 ~]#

Copyright © Linux教程網 All Rights Reserved