zoukankan      html  css  js  c++  java
  • linux系列(十五):tail命令

    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 a.txt

    输出:

    felix@felix-computer:~/test$ cat a.txt 
    第0行
    第1行
    第2行
    第3行
    第4行
    第5行
    第6行
    第7行
    第8行
    第9行
    felix@felix-computer:~/test$ tail -n 5 a.txt 
    第5行
    第6行
    第7行
    第8行
    第9行
    felix@felix-computer:~/test$ 

    (2)、循环查看文件内容

    命令:

        tail -f a.log

    输出:

    felix@felix-computer:~/test$ ping baidu.com > a.log &
    [1] 4581
    felix@felix-computer:~/test$ tail -f a.log 
    PING baidu.com (123.125.115.110) 56(84) bytes of data.
    64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=50 time=6.38 ms
    64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=50 time=6.33 ms
    64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=50 time=6.04 ms
    64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=4 ttl=50 time=9.79 ms
    64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=5 ttl=50 time=6.10 ms
    64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=6 ttl=50 time=11.3 ms

    (3)、从第六行开始显示内容

    命令:

        tail -n +6 a.txt

    输出:(注意和不加+的区别)

    felix@felix-computer:~/test$ cat a.txt 
    第0行
    第1行
    第2行
    第3行
    第4行
    第5行
    第6行
    第7行
    第8行
    第9行
    felix@felix-computer:~/test$ tail -n +6 a.txt 
    第5行
    第6行
    第7行
    第8行
    第9行
    felix@felix-computer:~/test$
  • 相关阅读:
    Leetcode 811. Subdomain Visit Count
    Leetcode 70. Climbing Stairs
    Leetcode 509. Fibonacci Number
    Leetcode 771. Jewels and Stones
    Leetcode 217. Contains Duplicate
    MYSQL安装第三步报错
    .net 开发WEB程序
    JDK版本问题
    打开ECLIPSE 报failed to load the jni shared library
    ANSI_NULLS SQL语句
  • 原文地址:https://www.cnblogs.com/felixwang2/p/9999009.html
Copyright © 2011-2022 走看看