Linux常用命令之head和tail

释放双眼,带上耳机,听听看~!

Linux中常用head和tail命令来查看文件中的开头和结尾指定区块的信息,并显示到标准输出。

Head

head 命令默认显示文件的前10行的文件内容。如果没有参数或者参数为’-‘ 则从标准输入读取10行。

-c, --bytes=[-]K
 print the first K bytes of each file; with the leading '-',print all but the last K bytes of each file

-n, --lines=[-]K
 print the first K lines instead of the first 10; with the lead‐
 ing '-', print all but the last K lines of each file

-v, --verbose
 always print headers giving file names

-c num , -num 显示前多少字节的内容,-c -num 显示除最后num字节的其它所有内容

-n num ,-num显示前多少行的内容,-n -num显示除最的num行的其它所有内容

-v 显示文件名

Tail

在标准输出上显示每个文件的最后10行. 如果多于一个文件,会依次显示, 并在每个文件显示的首部给出文件名. 如果没有文件或是-,那么就从标准输入上读取.

-c, --bytes=K
 output the last K bytes; alternatively, use -c +K to output
 bytes starting with the Kth of each file

-f, --follow[={name|descriptor}]
 output appended data as the file grows; -f, --follow, and--follow=descriptor are equivalent

-F same as --follow=name --retry

-n, --lines=K
 output the last K lines, instead of the last 10; or use -n +K
 to output lines starting with the Kth

--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not changed size
 after N (default 5) iterations to see if it has been unlinked
 or renamed (this is the usual case of rotated log files). With
 inotify, this option is rarely useful.

--pid=PID
 with -f, terminate after process ID, PID dies

-q, --quiet, --silent
 never output headers giving file names

--retry
 keep trying to open a file even when it is or becomes inacces‐
 sible; useful when following by name, i.e., with --follow=name

-s, --sleep-interval=N
 with -f, sleep for approximately N seconds (default 1.0)
 between iterations. With inotify and --pid=P, check process P
 at least once every N seconds.

-v, --verbose
 always output headers giving file names

--help display this help and exit

--version
 output version information and exit

–retry

即使tail开始时就不能访问或者在tail运行后不能访问,也仍然不停地尝试打开文件. — 只与-f合用时有用.

-c, –bytes=K

输出最后K个字节

-f, –follow[={name|descriptor}]

当文件增长时,输出后续添加的数据; -f, –follow以及 –follow=descriptor 都是相同的意思

-n, –lines=K

输出最后K行,而非默认的最后10行

–max-unchanged-stats=N

参看texinfo文档(默认为5)

–max-consecutive-size-changes=N

参看texinfo文档(默认为200)

–pid=PID

与-f合用,表示在进程ID,PID死掉之后结束.

-q, –quiet, –silent

从不输出给出文件名的首部

-s, –sleep-interval=S

与-f合用,表示在每次反复的间隔休眠S秒

-v, –verbose

总是输出给出文件名的首部

–help

显示帮助信息后退出

–version

输出版本信息后退出

如果K为前边带上+号,即+k,则表示从第K行开始直到文件结束。

给TA打赏
共{{data.count}}人
人已打赏
Linux

Linux常用命令之cat,more,less

2018-8-22 16:08:53

LinuxWordPress

Apache重写规则之.htaccess

2018-8-29 11:07:11

免责声明
本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站除大叔原创外的资源均来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。如有侵权请通过私信与我们联系处理。敬请谅解!
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
有新私信 私信列表
搜索