美文网首页
每天一个linux命令14-tail

每天一个linux命令14-tail

作者: 1519f8ccc7b0 | 来源:发表于2017-04-18 20:01 被阅读0次

1. 命令解析

命令用途

把文件的末尾N行显示到标准输出,默认显示10行,还可通过 tail -f file 来持续输出文件的数据。

命令格式

tail [OPTION]... [FILE]...

命令参数

-c, --bytes=K output the last K bytes; or use -c +K to output
bytes starting with the Kth of each file
-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=K output the last K lines, instead of the last 10;
or use -n +K to output 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 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

2. 示例

2.1 显示文件末尾10行

[root@test headTest]# tail hisotry.log 
  213  less history.log 
  214  cd /root/test
  215  ls
  216  mkdir headTest
  217  ls
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log

2.2 显示文件末尾5行 -n

[root@test headTest]# tail -5 hisotry.log 
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log

2.3 实时跟踪文件(默认1秒刷新一次) -f

[root@test headTest]# ping localhost > ping.log&
[1] 4971
[root@test headTest]# tail -f ping.log
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.011 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.051 ms

通过CTRL+C结束实时监控

2.4 定时实时跟踪文件 -fs

[root@test headTest]# ping localhost > ping.log&
[2] 5116
[root@test headTest]# tail -fs2 ping.log
64 bytes from localhost (127.0.0.1): icmp_seq=10 ttl=64 time=0.036 ms
64 bytes from localhost (127.0.0.1): icmp_seq=220 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=221 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=222 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=223 ttl=64 time=0.081 ms

每隔2秒刷新,显示文件最新内容

2.5 从第5行开始显示剩余所有内容 -n +N

[root@test headTest]# tail -n +5 ping.log
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.081 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.050 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.029 ms
...省略...

2.6 显示多个文件

root@test headTest]# tail -n 5 hisotry.log ping.log 
==> hisotry.log <==
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log

==> ping.log <==
64 bytes from localhost (127.0.0.1): icmp_seq=331 ttl=64 time=0.062 ms
64 bytes from localhost (127.0.0.1): icmp_seq=332 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=333 ttl=64 time=0.037 ms
64 bytes from localhost (127.0.0.1): icmp_seq=334 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=335 ttl=64 time=0.025 ms

2.7 不显示文件名 -q

[root@test headTest]# tail -qn 5 hisotry.log ping.log 
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log
64 bytes from localhost (127.0.0.1): icmp_seq=373 ttl=64 time=0.023 ms
64 bytes from localhost (127.0.0.1): icmp_seq=374 ttl=64 time=0.023 ms
64 bytes from localhost (127.0.0.1): icmp_seq=375 ttl=64 time=0.044 ms
64 bytes from localhost (127.0.0.1): icmp_seq=376 ttl=64 time=0.032 ms
64 bytes from localhost (127.0.0.1): icmp_seq=377 ttl=64 time=0.030 ms

相关文章

  • 每天一个linux命令14-tail

    1. 命令解析 命令用途: 把文件的末尾N行显示到标准输出,默认显示10行,还可通过 tail -f file 来...

  • Linux 常用命令汇总

    转载自伯乐在线每天一个 Linux 命令系列 每天一个 Linux 命令(1):ls命令 每天一个 Linux 命...

  • Linux 常用命令汇总

    转载自骑摩托马斯Linux 常用命令汇总 每天一个 Linux 命令(1):ls命令 每天一个 Linux 命令(...

  • 网络常用命令

    1. ss 每天一个linux命令(57):ss命令 2. netstat 每天一个linux命令(56):net...

  • linux之chown更改文件所属用户或者组

    转载链接 每天一个linux命令(30): chown命令 linux命令--chown 说明 chown将指定文...

  • Linux常用基本命令

    Linux命令大全查询每天一个 Linux 命令 命令 --help:帮助信息 man 命令 :使用手册 ctr+...

  • Linux

    每天一个Linux命令

  • 每天一个Linux命令:scp命令

    每天一个linux命令:scp命令 scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令...

  • 每天一个linux命令

    开始详细系统的学习linux常用命令,坚持每天一个命令,所以这个系列为每天一个linux命令。学习的主要参考资料为...

  • tar 命令 压缩解压缩

    参考文章:每天一个linux命令(28):tar命令linux下使用tar命令 解压缩tar.gz 解压缩tar.xz

网友评论

      本文标题:每天一个linux命令14-tail

      本文链接:https://www.haomeiwen.com/subject/jdeqzttx.html