cat:显示文本文件
使用cat命令可以显示文本文件的内容,也可以把几个文件的内容追加到另一个文件中。如果没有指定文件,或者文件为“-”,那么就从标准输入读取。
命令语法:
cat [选项] [文件]
选项:
-n :对输出的所有行编号
-b :对非空输出行编号
-s :当遇到多行的空行时,将其显示为一行的空白行
-E :在每行结束处显示$
例子:
显示/etc/inittab 文件的内容 [root@jdyun ~]# cat /etc/inittab # inittab is only used by upstart for the default runlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:3:initdefault:
把文件test1的内容加上行号输入到test2文件中 [root@jdyun data]# cat -n test1>>test2 [root@jdyun data]# cat test2 1 sfsg 2 faqeg 3 agsg
使用cat命令创建文件test1文件 [root@jdyun data]# cat >test1<<EOF #开头和结尾的EOF可用任意字符替换,习惯上使用EOF sfsg faqeg agsg EOF [root@jdyun data]# cat test1 #查看tes1中的文件内容 sfsg faqeg agsg
本文出自 “Linux学习记录” 博客,请务必保留此出处http://zjmlinux.blog.51cto.com/4684186/1982955
原文地址:http://zjmlinux.blog.51cto.com/4684186/1982955