天天看点

每天进步一点点——linux——tail一            简介二            命令格式三            常用参数四            所有参数五            示例二            参考资料

一            简介

tail命令是从文件末尾输出文件,这个命令常用于看日志。

二            命令格式

tail[必要参数][选择参数][文件]  

三            常用参数

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

                即时输出文件变化后追加的数据。

  -n  <行数>          显示指定行数

四            所有参数

-c, --bytes=K        显示指定的字节数

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

                即时输出文件变化后追加的数据。

                        -f, --follow 等于--follow=descriptor

 -F            即--follow=name--retry

  -n,--lines=K           显示指定的行数

     --max-unchanged-stats=N

                           with --follow=name,reopen a FILE which has not

                           changed size after N(default 5) iterations

                           to see if it hasbeen unlinked or renamed

                           (this is the usualcase of rotated log files).

                           With inotify, thisoption is rarely useful.

     --pid=PID         同 -f 一起使用,当 PID 所对应的进程死去后终止

  -q,--quiet, --silent 不输出给出文件名的头

     --retry           即使目标文件不可访问依然试图打开;在与参数

                        --follow=name 同时使用时常常有用。

  -s,--sleep-interval=N   with -f, sleep forapproximately N seconds

                             (default 1.0)between iterations.

                           With inotify and--pid=P, check process P at

                           least once every Nseconds.

  -v,--verbose            always outputheaders giving file names

     --help            显示此帮助信息并退出

     --version         显示版本信息并退出

五            示例

5.1  显示文件后3行

[[email protected]~]# tail -n 3 install.log

安装 words-3.0-17.el6.noarch

安装 redhat-indexhtml-6-1.el6.noarch

*** FINISHED INSTALLING PACKAGES***[[email protected] ~]#

5.2  显示文件最后100个字节

[[email protected]~]# tail -c 100 install.log

 words-3.0-17.el6.noarch

安装 redhat-indexhtml-6-1.el6.noarch

*** FINISHED INSTALLING PACKAGES***[[email protected] ~]# 

5.1  动态显示文件

[[email protected]~]# ping 11.10.111.254 >aaa.log &

[1] 10653

[[email protected]~]# tail -f aaa.

aaa.log aaa.txt 

[[email protected]~]# tail -f aaa.log

PING 11.10.111.254 (11.10.111.254) 56(84)bytes of data.

64 bytes from 11.10.111.254: icmp_seq=1ttl=255 time=1.27 ms

64 bytes from 11.10.111.254: icmp_seq=2ttl=255 time=1.29 ms

64 bytes from 11.10.111.254: icmp_seq=3ttl=255 time=1.99 ms

64 bytes from 11.10.111.254: icmp_seq=4 ttl=255time=1.67 ms

64 bytes from 11.10.111.254: icmp_seq=5ttl=255 time=1.94 ms

64 bytes from 11.10.111.254: icmp_seq=6ttl=255 time=1.67 ms

64 bytes from 11.10.111.254: icmp_seq=7ttl=255 time=2.58 ms

64 bytes from 11.10.111.254: icmp_seq=8ttl=255 time=1.14 ms

64 bytes from 11.10.111.254: icmp_seq=9ttl=255 time=1.35 ms

64 bytes from 11.10.111.254: icmp_seq=10ttl=255 time=1.65 ms

64 bytes from 11.10.111.254: icmp_seq=11ttl=255 time=2.00 ms

64 bytes from 11.10.111.254: icmp_seq=12ttl=255 time=2.36 ms

注意,此实验操作完成后记得要输入kill  10653(看上面ping命令后面的那个数字)

二            参考资料

http://vbird.dic.ksu.edu.tw/

http://gnu.org/licenses/gpl.html

man手册

继续阅读