鸟哥个人是比较少用 cat 啦!毕竟当你的文件内容的行数超过 40 行以上,嘿嘿!根本来不及在屏幕上看到结果! 所以,配合等一下要介绍的 more 或者是 less 来执行比较好!此外,如果是一般的 DOS 文件时,就需要特别留意一些奇奇怪怪的符号了, 例如断行与 [tab] 等,要显示出来,就得加入 -A 之类的选项了!
[root@study ~]# tac /etc/issue
Kernel \r on an \m
\S
# 嘿嘿!与刚刚上面的范例一比较,是由最后一行先显示喔!
[root@study ~]# nl [-bnw] 文件
选项与参数:
-b :指定行号指定的方式,主要有两种:
-b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
-b t :如果有空行,空的那一行不要列出行号(默认值);
-n :列出行号表示的方法,主要有三种:
-n ln :行号在屏幕的最左方显示;
-n rn :行号在自己字段的最右方显示,且不加 0 ;
-n rz :行号在自己字段的最右方显示,且加 0 ;
-w :行号字段的占用的字符数。
范例一:用 nl 列出 /etc/issue 的内容
[root@study ~]# nl /etc/issue
1 \S
2 Kernel \r on an \m
# 注意看,这个文件其实有三行,第三行为空白(没有任何字符),
# 因为他是空白行,所以 nl 不会加上行号喔!如果确定要加上行号,可以这样做:
[root@study ~]# nl -b a /etc/issue
1 \S
2 Kernel \r on an \m
3
# 呵呵!行号加上来啰~那么如果要让行号前面自动补上 0 呢?可这样
[root@study ~]# nl -b a -n rz /etc/issue
000001 \S
000002 Kernel \r on an \m
000003
# 嘿嘿!自动在自己字段的地方补上 0 了~默认字段是六位数,如果想要改成 3 位数?
[root@study ~]# nl -b a -n rz -w 3 /etc/issue
001 \S
002 Kernel \r on an \m
003
# 变成仅有 3 位数啰~
[root@study ~]# more /etc/man_db.conf
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
.....(中间省略).....
--More--(28%) <== 重点在这一行喔!你的光标也会在这里等待你的指令
[root@study ~]# more /etc/man_db.conf
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
....(中间省略)....
/MANPATH <== 输入了 / 之后,光标就会自动跑到最下面一行等待输入!
[root@study ~]# less /etc/man_db.conf
#
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
.....(中间省略).....
: <== 这里可以等待你输入指令!
[root@study ~]# head [-n number] 文件
选项与参数:
-n :后面接数字,代表显示几行的意思
[root@study ~]# head /etc/man_db.conf
# 默认的情况中,显示前面十行!若要显示前 20 行,就得要这样:
[root@study ~]# head -n 20 /etc/man_db.conf
范例:如果后面100行的数据都不打印,只打印/etc/man_db.conf的前面几行,该如何是好?
[root@study ~]# head -n -100 /etc/man_db.conf