cat:从第一行开始显示内容
tac:从最后一行开始显示内容
nl :显示时输出行号
more:一页一页翻
less:一页一页翻
head:只看头几行
tail:只看尾巴几行
more:file perusal filter for crt viewing
more is a filter for paging through text one screenful at a time(文本分页器)
less: opposite of more
less is a program similar to more
head:output the first part of files
print the first 10 lines of each file to standard output.
-n(--lines=[-]K):print the first K lines instead of the first 10; with the leading '-',print all but the last K lines of each file.
tail:output the last part of files
-n(--lines=K):output the last K lines, instead of the last 10,or use -n +k to output lines starting with Kth.
-f(--follow[={name|descriptor}]):output appended data as the file grows;-f,--follow,and --follow=descriptor are equivalent
cd /opt/test
ls -l test.js
-rw-r--r-- 1 root root 106667 Aug 23 19:31 test.js
more test.js
:f
q
"test.js" line 1481
空格键:下一页
回车键: 下一行
/字符串:向下搜索字符串,重复向下搜索,n
b(ctrl+b):往回翻页
:f:显示当前文件名和所在行数
q:离开,不显示文件内容
cd /opt/test
ls -l test.js
-rw-r--r-- 1 root root 106667 Aug 23 19:31 test.js
less test.js
空格键: 下一页
回车键:下一行
home:第一页
end:最后一页
page down:下一页
page up:上一页
/字符串:向下搜索字符串,重复向下搜索:n;反向重复搜索:N
?字符串:向上搜索字符串,重复向上搜索:n;反向重复搜索:N
q:离开,不显示文件内容
more test.js / less test.js 之后的操作相同点挺多,但比较而言,less更好用。
less test.js 和 man page 很相同,因为man page 就是调用less来显示文件内容的
cd /opt/test
ls -l test.js
-rw-r--r-- 1 root root 106667 Aug 23 19:31 test.js
head test.js
默认显示前10行
head -n 20 test.js
显示前20行
head -n -20 test.js
除了最后20行,显示前面所有行
cd /opt/test
ls -l test.js
-rw-r--r-- 1 root root 106667 Aug 23 19:31 test.js
tail test.js
显示最后10行
tail -n 20 test.js
显示最后20行
tail -n +20 test.js
除了最开始20行,显示后面所有行
head -n 20 test.js
显示test.js的前20行
tail -n 10 test.js
显示test.js的最后20行
head -n 20 test.js | tail -n 10
显示test.js的第11~20行(先取test.js的前20行,再取这20行的后10行,所以最终显示的是test.js的第11~20行)
监测文件内容变化
tail -f /var/log/messages
退出监测
ctrl+c