美文网首页
shell tail

shell tail

作者: 水平 | 来源:发表于2016-12-13 16:28 被阅读26次

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 5 log2014.log
2014-09
2014-10
2014-11
2014-12
==============================[root@localhost test]#
说明:
显示文件最后5行内容

实例2:循环查看文件内容
命令:
tail -f test.log
输出:
[root@localhost ~]# ping 192.168.120.204 > test.log &
[1] 11891[root@localhost ~]# tail -f test.log
PING 192.168.120.204 (192.168.120.204) 56(84) bytes of data.
64 bytes from 192.168.120.204: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 192.168.120.204: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.120.204: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=4 ttl=64 time=0.027 ms
64 bytes from 192.168.120.204: icmp_seq=5 ttl=64 time=0.032 ms
64 bytes from 192.168.120.204: icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from 192.168.120.204: icmp_seq=7 ttl=64 time=0.030 ms
64 bytes from 192.168.120.204: icmp_seq=8 ttl=64 time=0.029 ms
64 bytes from 192.168.120.204: icmp_seq=9 ttl=64 time=0.044 ms
64 bytes from 192.168.120.204: icmp_seq=10 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=11 ttl=64 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
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================
[root@localhost test]# tail -n +5 log2014.log
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================

相关文章

  • shell tail

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail...

  • 巧记Shell 命令的^和$

    In shell command, ^ stands for head and $ stands for tail...

  • Docker命令

    获取容器ip 关闭多个容器 tail容器log 创建镜像 进入容器shell

  • 文件、目录权限/归属控制

    文件、目录权限归属: r:cat 、less、head、tail w:vim 、>、 >> x:shell脚本编写...

  • shell的分类

    shell的分类 文件查看 cat/more/less/tail/tee/>/< 文本处理 grep/aw...

  • Shell tail 显示文件的尾部

    默认情况下,打印每个指定输入的最后10行内容。 指定打印文件的最后 INT 行。 即时打印文件中新写入的行。使用这...

  • Linux中使用tail命令查看系统日志

    1、tail命令介绍 tail-f:1)tail(尾部) tail命令从指定点开始将文件写到标准输出;2)使用t...

  • 共读—— You are a Badass Day 2

    the tail end of a heated tiebreakerthe tail end = the fin...

  • Linux查询日志常用命令

    常用命令: 详情如下: tail tail -f test.log tail -100 test.log -- 显...

  • 15.tail

    tail 命令所在路径: /usr/bin/tail 执行权限: 所有用户 语法: tail [文件名] 功能...

网友评论

      本文标题:shell tail

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