Welcome 微信登录

首页 / 操作系统 / Linux / 13个Cat命令管理(显示,排序,建立)文件实例

在Linux系统中,大多数配置文件、日志文件,甚至shell脚本都使用文本文件格式,因此,Linux系统存在着多种文本编辑器,但当你仅仅想要查看一下这些文件的内容时,可使用一个简单的命令-cat。cat手册里这样描述:
cat命令读取文件内容,并输出到标准设备上面
cat是一条linux内置命令. 几乎所有linux发行版都内置(译注:或者说我从未听说过不内置cat命令的发行版)。接下来,让我们开始学习如何使用.

1. 显示文件内容

最简单的方法是直接输入‘cat file_name’.# cat /etc/issueCentOS release 5.10 (Final)Kernel on an m

2. 同时显示行号

当在读取内容很多的配置文件时,如果同时显示行号将会使操作变简单,加上-n参数可以实现.# cat -n /etc/ntp.conf1 # 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参数,-b也可以显示行号。区别在于-b只在非空行前显示行号。#cat -b /etc/ntp.conf1 # 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 noquery5 # 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参数在每行结尾使用 $ 表示换行符。如下所示 :# 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命令与其它命令分屏显示。使用管道符 ( | )来连接。# cat /proc/meminfo | less# cat /proc/meminfo | more在less与more显示结果的区别在于less参数可pageup及pagedown上下翻滚。而more仅能使用空格向下翻屏。

8. 同时查看2个文件中的内容

位于/root文件夹里有两个文件取名linux及desktop,每个文件含有以下内容 :Linux : Ubuntu, centos, RedHat, mint and slackwareDesktop : gnome kde, xfce, enlightment, and cinnamon当你想同时查看两文件中的内容时,可按如下方法 :# cat /root/linux /root/desktopubuntucentosredhatmintslackwaregnomekdexfceenlightmentcinnamon更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-12/93540p2.htm相关阅读:11个很少有人知道但很有用的Linux命令 http://www.linuxidc.com/Linux/2013-10/92095.htmLinux下常用文本处理命令 http://www.linuxidc.com/Linux/2013-10/91825.htmLinux常用网络命令整理 http://www.linuxidc.com/Linux/2013-09/90503.htmLinux 命令整理 http://www.linuxidc.com/Linux/2013-09/89936.htmLinux 新手必学的 20 个命令 http://www.linuxidc.com/Linux/2013-08/88477.htm
  • 1
  • 2
  • 下一页
Linux中添加管理员权限问题:xxx is not in the sudoers file. This incident will be reported.Ubuntu 13.10 上安装 Freefilesync 同步软件相关资讯      cat命令  cat 
  • Linux教程:pwd, cd, ls, cat,   (今 16:11)
  • cat命令利用Linux重定向合并文件  (01/20/2015 19:34:27)
  • Linux cat命令用法  (11/09/2012 20:06:42)
  • Linux命令教程:cat命令 查看文件内  (08/06/2015 15:53:07)
  • Linux命令之cat  (05/07/2013 08:38:01)
  • Linux cat more less显示文件的区  (07/30/2012 14:50:23)
本文评论 查看全部评论 (0)
表情: 姓名: 字数