[一文一命令]tail命令详解
2013-12-20 15:35
387 查看
tail
名称:tail - output the last part of files 输出文件最后的那部分内容功能描述:tail命令从指定点开始将文件写到标准输出,使用-f选项可以方便的查阅正在改变的日志文件,tail –f filename会到filename尾部的内容输出并且不断的刷新,可以看到不断更新的内容。
参数:
-f 循环读取 follow
-v 显示详细的处理信息
-n 显示行数
-p --pid 与-f合用,表示当-f所指定的文件,在所产生它的程序死掉后,结束。通过pid来识别。
-s –sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒。
-q –quiet 从不输出头给文件。
实例:
1)显示文件末尾内容[root@bogon ~]# tail -n 10 /var/log/messages
Apr 25 22:25:16 bogon last message repeated 14times
Apr 25 22:26:21 bogon last message repeated 29times
Apr 25 22:30:59 bogon last message repeated 2 times
Apr 25 22:31:20 bogon last message repeated 12times
Apr 25 22:31:22 bogon dhclient: DHCPREQUEST on eth0to
2)循环查看文件内容,不断更新,当pid死掉时查看结束。[root@bogon ~]# ping 192.168.40.1 > test.log&
[1] 4911
[root@bogon ~]# tail -n 3 -f test.log
64 bytes from 192.168.40.1: icmp_seq=11 ttl=255time=0.859 ms
64 bytes from 192.168.40.1: icmp_seq=12 ttl=255time=0.767 ms
64 bytes from 192.168.40.1: icmp_seq=13 ttl=255time=0.564 ms
64 bytes from 192.168.40.1: icmp_seq=14 ttl=255time=0.748 ms
64 bytes from 192.168.40.1: icmp_seq=15 ttl=255time=0.724 ms
[root@bogon ~]# jobs
[1]+ Running ping192.168.40.1 > test.log &
[root@bogon ~]# fg 1
ping 192.168.40.1 > test.log
说明:显示把ping 192.168.40.1 >test.log置入到后台执行。当我们查看完成之后,需要通过命令jobs 查看后台工作 fg 1 把它调回到前台来,然后通过ctrl+c 来结束。
另:有一点就是ping 192.168.40.1 > test.log 那么test.log的内容不是应该就只有一条,因为后来的覆盖掉前面的。但我都结束之后cat查看test.log的内容却是很多?
3)排除前内容最前面的5行内容,从第5行开始显示。
[root@bogon ~]# tail -n +5 2.log
5
6
7
8
9
-----------------------后续自我小结--------------------
tail主要就是用来查看我们的文件,从文章后面开始查看。主要的一个功能就是-f follow持续的查看
文件的更新内容。主要的还是体现在能够查看内容。当然能够查看到的内容都是可以被处理的:比如进行选择,awk截取显示,定向到另一个文件等等..这个就是灵活的地方。这个就要和我们的处理命令结合在一起了。
--------------------------------------------------------
相关文章推荐
- tail 命令详解
- [一文一命令]touch命令详解
- [一文一命令]vi命令详解
- Linux命令详解 -- cat tac more less head tail
- nux中tail 命令使用详解(显示最尾部的内容)
- Linux 命令head和tail常见用法详解
- linux tail 命令详解!Linux 文件内容查看工具介绍
- linux tail命令的使用方法详解
- [一文一命令]grep命令详解
- 文件显示命令:cat、more、less、tail、touch详解
- Linux tail 命令详解
- ceph存储 centos下tail命令详解
- 【Linux命令详解】12、文本内容显示―[ cat、tac、more、less、tail、head]
- Linux命令详解之—tail命令
- Linux中tail命令用法详解
- linux tail命令使用详解
- shell: 文件显示命令cat、more、less、tail、touch、od详解
- linux shell 脚本攻略学习14--head命令详解,tail命令详解
- linux tail命令的使用方法详解
- head和tail命令详解