tail 命令
tail命令可以将文件指定位置到文件结束的内容写到标准输出。
使用tail命令的-f选项可以方便的查阅正在改变的日志文件。
tail -f filename会把文件里最尾部的内容显示在屏幕上,并且不断刷新,使你看到最新的文件内容。
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.
将每个文件的最后10行打印到标准输出。对于多个文件,在每个文件前面加上一个给出文件名的头。
With no FILE, or when FILE is -, read standard input.
没有文件时,或当文件为-时,读取标准输入。
Mandatory arguments to long options are mandatory for short options too.
长期权的强制参数对于短期权也是强制的。
-c, --bytes=[+]NUM
output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file
输出最后一个NUM字节;或者使用-c +NUM以每个文件的字节数开始输出
-f, --follow[={name|descriptor}]
output appended data as the file grows;
随着文件的增长,输出附加的数据;
an absent option argument means 'descriptor'
缺少的选项参数意味着“描述符”
-F same as --follow=name --retry
-n, --lines=[+]NUM
output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM
输出最后的NUM行,而不是最后10行;或者使用-n +NUM从行NUM开始输出
--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
与-f,终止后进程ID, PID模具
-q, --quiet, --silent
never output headers giving file names
永远不要输出带有文件名的头文件
--retry
keep trying to open a file if it is inaccessible
-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
总是输出带有文件名的头文件
-z, --zero-terminated
line delimiter is NUL, not newline
行分隔符是NUL,不是换行符
--help display this help and exit
--version
output version information and exit
NUM 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.
NUM可以有一个乘法器后缀: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.
- 输出最后的100个字符
tail -c 100 test.log
- 从第650个字符开始输出,一直到最后
tail -c +650 test.log
- 输出最后的5行
tail -n 5 test.log
- 从第196行开始输出,一直到最后
tail -n +196 test.log
- 输出指定文件的最后十行,同时继续监视文件内容有无变化,新增内容会继续输出,直到按下 [Ctrl-C] 组合键停止该命令。
tail -f test.log
- 指定多个文件并输出文件名
tail -v test.log test2.log
> test.log <
191 2018-09-08 15:49:15:724 MWPPA
192 2018-09-09 15:50:06:724 UWRQM
············
200 2018-09-17 15:58:13:725 PHKIZ
> test2.log <
391 2019-03-27 22:00:38:800 GKAVS
392 2019-03-28 22:01:39:801 FZZQO
···········
400 2019-04-05 22:09:42:802 EMIYR
- 指定多个文件不输出文件名
tail -q test.log test2.log
head命令
head命令用于显示文件的开头的内容。在默认情况下,head命令显示文件的头10行内容。
HEAD(1) User Commands HEAD(1)
NAME
head - output the first part of files
SYNOPSIS
head [OPTION]... [FILE]...
DESCRIPTION
Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.
将每个文件的前10行打印到标准输出。对于多个文件,在每个文件前面加上一个给出文件名的头。
With no FILE, or when FILE is -, read standard input.
没有文件时,或当文件为-时,读取标准输入。
Mandatory arguments to long options are mandatory for short options too.
长期权的强制参数对于短期权也是强制的。
-c, --bytes=[-]NUM
print the first NUM bytes of each file; with the leading '-', print all but the last NUM bytes of each file
打印每个文件的第一个NUM字节;以“-”开头,打印每个文件的所有数字字节,但最后一个数字字节除外
-n, --lines=[-]NUM
print the first NUM lines instead of the first 10; with the leading '-', print all but the last NUM lines of each file
打印第一行数字,而不是前10行;以“-”开头,打印每个文件的除最后几行以外的所有数字行
-q, --quiet, --silent
never print headers giving file names
永远不要打印带有文件名的头文件
-v, --verbose
always print headers giving file names
总是打印标题给出文件名
-z, --zero-terminated
line delimiter is NUL, not newline
行分隔符是NUL,不是换行符
--help display this help and exit
--version
output version information and exit
NUM 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.
AUTHOR
Written by David MacKenzie and Jim Meyering.
REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report head translation bugs to <http://translationproject.org/team/>
COPYRIGHT
Copyright © 2016 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
tail(1)
Full documentation at: <http://www.gnu.org/software/coreutils/head>
or available locally via: info '(coreutils) head invocation'
GNU coreutils 8.25 February 2017 HEAD(1)
Manual page head(1) line 1/55 (END) (press h for help or q to quit)
- 输出开始的100个字符
head -c 100 test.log
- 从开始一直到倒数第6500个字符,进行输出
head -c -6500 test.log
+或空,从头计数
-,从尾计数
- 指定多个文件并输出文件名
head -v test.log test2.log
> test.log <
1 2018-03-02 12:39:06:698 YZXBB
··········
10 2018-03-11 12:48:06:702 ALXQQ
> test2.log <
201 2018-09-18 18:50:25:778 ZHWKD
···········
210 2018-09-27 18:59:39:779 HDRAT