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行开始直到文件结束。