linux tail命令,head命令,more命令,cat命令,less命令使用详解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wudinaniya/article/details/83413474

一 tail命令

linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗来讲,就是把某个文档文件的最后几行显示在终端上,假设该文档文件有更新,tail会自己主动刷新,确保你看到最新的档案内容。

tail命令用来看文件的结尾。

tail 命令语法:

tail -f filename
说明:监视filename文件的尾部内容(默认10行,相当于增加参数 -n 10,即 tail -f -n 10 filename),刷新显示在屏幕上。退出,按下Ctrl+C

tail -n 20 filename
说明:显示filename最后10行。

[root@localhost log]# tail -n 20 websender.log   显示文档的最后20行内容,会自动退出。

[root@localhost log]# tail -f -n 20 websender.log   显示文档的最后20行内容,文档有更新,自动刷新,按Ctrl+C 退出。

[root@localhost log]# tail -n 20 -f websender.log   显示文档的最后20行内容,文档有更新,自动刷新,按Ctrl+C 退出。

二 head命令

head命令用来显示文档文件的开头至标准输出中,默认head命令打印文件的开头10行。

[root@localhost log]# head websender.log  显示文档的开头10行,会自动退出。

[root@localhost log]# head -n 5 websender.log   显示文档的开头5行,会自动退出。

三 more命令 

more命令 分页显示文件内容,一次显示一屏文本,满屏后停下来,并且在屏幕的底部出现一个提示信息,给出至今已显示的该文件的百分比,方便逐页阅读。

按回车键往下一行显示,按空格键往下一页显示,按b键就会往回(back)一页显示。

[root@localhost log]# more websender.log     一次显示一屏文本

[root@localhost log]# more -5 websender.log  每次显示5行,不清屏

[root@localhost log]# more -p -5 websender.log   每次显示5行,清屏显示,eg:

四 cat命令

从第一行开始显示文件内容

五 less命令

与more相似,但支持向前翻页

猜你喜欢

转载自blog.csdn.net/wudinaniya/article/details/83413474