tail 命令详解
Linux -- tail 查看文件内容
TAIL(1) User Commands TAIL(1)
NAME 名称
tail - output the last part of files 打印文件的最后一部分
SYNOPSIS 大纲
tail [OPTION]... [FILE]...
DESCRIPTION 说明
Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input.
输出每个文件的后10行。如果不只一个文件,依次输出每个文件,在每个文件输出前输出文件名称。当没有指定文件或文件占位符是'-'时,从标准输入设备读取。
Mandatory arguments to long options are mandatory for short options too.
对于长选项必须的参数,对于短选项也是必须的。
-c, --bytes=K
output the last K bytes; or use -c +K to output bytes starting with the Kth of each file
输出每个文件的最后K字节内容;或使用-c +K从每个文件的开头算起的第K字节开始输出。
-f, --follow[={name|descriptor}]
output appended data as the file grows;
当文件增长时,显示文件的追加内容。
an absent option argument means 'descriptor'
默认缺省参数为'descriptor'。
-F
same as --follow=name --retry
类似于--follow=name --retry。
-n, --lines=K
output the last K lines, instead of the last 10; or use -n +K to output starting with the Kth
输出每个文件的最后K行内容,而不是默认的10行;或使用-n +K从每个文件的开头算起的第K行开始输出。
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not
结合--follow=name,重新打开一个没有变化的文件。
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
重新打开一个在N次迭代后没有改变大小的文件来看它是否被解除连接或重命名(这是循环日志文件的通常情况);结和inotify结合,这个选项很少使用。
--pid=PID
with -f, terminate after process ID, PID dies
与-f合用,在进程ID,PID死掉后结束。
-q, --quiet, --silent
never output headers giving file names
总是在开头不输出文件名称。
--retry
keep trying to open a file if it is inaccessible
不停地尝试打开文件,只与-f合用时有用。
-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
与-f合用,每两次检查间隔休眠N秒钟;结合inotify和--pid使用时,在每个N秒种内至少检测一次进程P的状态。
-v, --verbose
always output headers giving file names
总是在开头输出文件名称。
--help display this help and exit
显示此命令的帮助信息并退出。
--version
output version information and exit
输入版本信息并退出。
If the first character of K (the number of bytes or lines) is a '+', print beginning with the Kth item from the start of each file, otherwise, print the last K items in the file. K may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.
如果K(字节或者行数)的第一个字符为'+',那么从每个文件的开头算起的第K项开始显示,否则, 显示该文件的最后K项。K可以有一个乘数后缀:b表示512,kB表示1000,K表示1024,MB表示1000*1000,M表示1024*1024,GB表示1000*1000*1000,G表示1024*1024*1024等,诸如此类的还有:T, P, E, Z, Y。
With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end. This default behavior is not desirable when you really want to track the actual name of the file, not the file descriptor (e.g., log rotation). Use --follow=name in that case. That causes tail to track the named file in a way that accommodates renaming, removal and creation.
使用--follow(-f)时,tail默认后接文件描述符,这意味着即使tail显示的文件改名了,tail仍然可以追踪到其末尾部分。如果你确实希望查询文件的实际名称而非文件描述符时(例如,日志轮转时),这种默认的操作就不是你所期望的了。在这种情况下应使用--follow=name。这将导致tail通过周期性地重新打开所指定的文件来追踪其是否被重命名、删除或重新创建。
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report tail translation bugs to <http://translationproject.org/team/>
AUTHOR
Written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering.
COPYRIGHT
Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for tail is maintained as a Texinfo manual. If the info
and tail programs are properly installed at your site, the command
info coreutils 'tail invocation'
should give you access to the complete manual.
tail 的完整文档是以Texinfo手册形式维护的. 如果info和tail程序都已经安装,那么命令:
info coreutils 'tail invocation'
应该会让你访问到整篇手册。
GNU coreutils 8.22 June 2014 TAIL(1)