tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的文件内容.

1.命令格式;

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

2.命令功能:

  用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理。常用查看日志文件。

3.命令参数:

  -f 循环读取

  -q 不显示处理信息

  -v 显示详细的处理信息

  -c<数目> 显示的字节数

  -n<行数> 显示行数

  --pid=PID 与-f合用,表示在进程ID,PID死掉之后结束.

  -q, --quiet, --silent 从不输出给出文件名的首部

  -s, --sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒

4.使用实例:

实例1:显示文件末尾内容

命令:

  tail -n 5 log2014.log

输出:

[root@localhost test]# tail -n  log2014.log
-
-
-
-
==============================
[root@localhost test]#

说明:显示文件最后5行内容

实例2:循环查看文件内容

命令:

  tail -f test.log

输出:

[root@localhost ~]# ping 192.168.120.204 > test.log &
[] [root@localhost ~]# tail -f test.log
PING 192.168.120.204 (192.168.120.204) () bytes of data.
bytes from 192.168.120.204: icmp_seq= ttl= time=0.038 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.036 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.033 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.027 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.032 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.026 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.030 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.029 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.044 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.033 ms
bytes from 192.168.120.204: icmp_seq= ttl= time=0.027 ms
[root@localhost ~]#

说明:

ping 192.168.120.204 > test.log & //在后台ping远程主机。并输出文件到test.log;这种做法也使用于一个以上的档案监视。用Ctrl+c来终止。

实例3:从第5行开始显示文件

命令:

  tail -n +5 log2014.log

输出:

[root@localhost test]# cat log2014.log
-
-
-
-
-
-
-
-
-
-
-
-
==============================
[root@localhost test]# tail -n + log2014.log
-
-
-
-
-
-
-
-
==============================

最新文章

  1. 20.SqlServer中if跟循环语句
  2. Ext.Net TreePanel 修改Icon图标
  3. 读书笔记:javascript高级技巧(二)
  4. linux keepalived+LVS 实现mysql 从库负载均衡
  5. Leetcode 88 Merge Sorted Array STL
  6. 修改tcp内核参数:somaxconn
  7. AUTH过程
  8. 【转】Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
  9. C#简单接口和继承示例详解——快速入门
  10. Redis学习笔记(3)——Redis的命令大全
  11. MD5 两次加密
  12. Trident中的DRPC实现
  13. AI 逻辑回归
  14. SQL Server死锁产生原因及解决办法 .
  15. 树莓派做路由器_配置防火墙filter和nat转发_转载
  16. keepalived+nginx实现HA高可用的web负载均衡
  17. MPP、SMP、NUMA概念介绍
  18. python模块整理30-uui模块
  19. Oracle的REGEXP_SUBSTR函数简单使用方法
  20. 如何在flink中传递参数

热门文章

  1. gdb 调试coredump文件过程:
  2. 转载:Service Mesh:重塑微服务市场--敖小剑
  3. Memcache课程
  4. 编译Python2.7.10
  5. C和C#两种方式实现邮件的简单发送
  6. Quartz(自动任务)中的触发器Trigger
  7. PHP运算符-算术运算符、三元运算符、逻辑运算符
  8. Mac OSX 如何在命令行中生成 md5、sha1、sha256 校验和
  9. 设计模式--模板方法模式C++实现
  10. 学习JVM