04-29 Linux查看文件内容、#cat -b /etc/ntp.conf 1 # Permit time synchronization our time resource but do not2 # permit the source to query or modify the service on this system3 restrict default kod nomodify notrap nopeer noquery4 restrict -6 default kod nomodify notrap nopeer noquery 5 # Permit all access over the loopback interface. This could be6 # tightened as well, but to do so would effect some of the7 # administration functions8 restrict 127.0.0.19 restrict -6 ::1
4. 显示tab制表符
当你想要显示文本中的tab制表位时. 可使用-T参数. 它会在输入结果中标识为 ^I .
# cat -T /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail.127.0.0.1^I^Ilocalhost.localdomain localhost::1^I^Ilocalhost6.localdomain6 localhost6
5. 显示换行符
-E参数在每行结尾使用 $ 表示换行符。 输入完成后
,让我们开始学习如何使用 。
1. 显示文件内容
最简单的方法是直接输入‘cat file_name’.
# cat /etc/issue CentOS release 5.10 (Final)Kernel \r on an \m
2. 同时显示行号
当在读取内容很多的配置文件时,我们使用以下命令 :
# cat < /root/linux | sort > linux-sort
此命令这样理解: 从/root/linux中读取内容,如下所示 :
# cat -E /etc/hosts # Do not remove the following line, or various programs$# that require network functionality will fail.$127.0.0.1 localhost.localdomain localhost$::1 localhost6.localdomain6 localhost6$
6. 同时显示制表符及换行符
当你想要同时达到-T及-E的效果, 可使用-A参数.
# cat -A /etc/hosts # Do not remove the following line, or various programs$# that require network functionality will fail.$127.0.0.1^I^Ilocalhost.localdomain localhost$::1^I^Ilocalhost6.localdomain6 localhost6$
7. 分屏显示
当文件内容显示超过了你的屏幕大小, 可结合cat命令与其它命令分屏显示。此时你可输入内容。 只需要使用 > 符号(大于号)即可输出生成到另一个文件。区别在于-b只在非空行前显示行号。 举例 :
# cat /root/linux >> /root/desktop # cat /root/desktop
它会将 /root/linux的内容追加到/root/desktop文件的末尾
。加上-n参数可以实现.
# cat -n /etc/ntp.conf 1 # Permit time synchronization our time resource but do not2 # permit the source to query or modify the service on this system3 restrict default kod nomodify notrap nopeer noquery4 restrict -6 default kod nomodify notrap nopeer noquery56 # Permit all access over the loopback interface. This could be7 # tightened as well, but to do so would effect some of the8 # administration functions9 restrict 127.0.0.110 restrict -6 ::1
3. 在非空格行首显示行号
类似于-n参数,接下来
,通过管道符对内容进行排序显示。
cat手册里这样描述:
cat命令读取文件内容 ,-b也可以显示行号。但当你仅仅想要查看一下这些文件的内容时
,
第二个文件的内容将会变成这样:
gnomekdexfceenlightmentcinnamonubuntucentosredhatmintslackware
13. 重定向输入
你可使用 <命令(小于号)将文件输入到cat中.
# cat < /root/linux
上面命令表示 /root/linux中的内容作为cat的输入。
12.向文件中追加内容
当你使用两个 > 符时, 会将第一个文件中的内容追加到第二个文件的末尾
。它会生成一个operatingsystem的文件。可按如下方法 :
# cat /root/linux /root/desktop ubuntucentosredhatmintslackwaregnomekdexfceenlightmentcinnamon
9. 排序显示
类似. 你也可以结合cat命令与其它命令来进行自定义输出. 如结合 sort ,
8. 同时查看2个文件中的内容
位于/root文件夹里有两个文件取名linux及desktop,大多数配置文件、如果同时显示行号将会使操作变简单, 顶: 24踩: 2595
评论专区