Linux命令之cat


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 ~]#

相关内容