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  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 + log2014.log

输出:

[root@localhost test]# cat log2014.log 

-

-

-

-

-

-

-

-

-

-

-

-

==============================

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

-

-

-

-

-

-

-

-

==============================

最新文章

  1. Mysql的连接状态
  2. oracle(sql)基础篇系列(三)&mdash;&mdash;数据维护语句、数据定义语句、伪列
  3. 【代码笔记】iOS-替换电话号码中间4位为-号
  4. (转)Linux grep
  5. hibernate----component-entity (人-地址-学校)
  6. Android中log使用方法
  7. GitHub上我收藏Java及Android的项目Demo
  8. JS中检测数据类型的四种方法
  9. (六)C#中判断空字符串的三种方法性能分析
  10. java:定义线程
  11. Systemd 入门教程:命令篇
  12. text code
  13. icon数目
  14. zabbix常见问题整理 持续更新……
  15. 如何把你的.net程序打包上传到nuget
  16. IDEA Junit4配置
  17. Oracle 数据库执行 操作系统的命令
  18. Finalize和Dispose的区别
  19. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT
  20. 机器学习之路:python 集成回归模型 随机森林回归RandomForestRegressor 极端随机森林回归ExtraTreesRegressor GradientBoostingRegressor回归 预测波士顿房价

热门文章

  1. Hibernate(七)一对一映射
  2. 心电图html js控件
  3. Oracle分组取第一条数据
  4. Banner尺寸多大最好!
  5. innodb_file_per_table
  6. 解决java.lang.OutOfMemoryError: unable to create new native thread问题
  7. JSTL不同版本和EL表达式的关联
  8. oracle10-11数据库下载
  9. 云ci自动构建实例 最佳实践
  10. 架构-LAMP特级学习(网站大存储量解决方案)