• Linux命令(94)之tail


    linux命令之tail

    1.tail介绍

    linux命令tail用来查看文件的最后N行内容,默认tail查看最后10行内容

    2.tail用法

    tail [参数] 文件

    tail常用参数
    参数说明
    -n显示文件默认N行,默认显示10行,可以不写
    -q隐藏文件名,在查看两个及以上文件名的情况下有效
    -v显示文件名
    -f(循环读取)监视 filename 文件的尾部内容(默认 10 行,相当于增加参数-n 10)刷新显示在屏幕上,退出按下 ctrl+c

    3.实例

    3.1.显示文件的最后5行内容

    命令:

    tail -n 5 a.txt

    1. [root@centos79-3 ~]# tail -n 5 a.txt
    2. 8
    3. 9
    4. 10
    5. 11
    6. 12
    7. [root@centos79-3 ~]#

    3.2.显示a.txt/b.txt文件的最后5行内容

    1. [root@centos79-3 ~]# tail -q -n 5 a.txt b.txt
    2. 8
    3. 9
    4. 10
    5. 11
    6. 12
    7. 8
    8. 9
    9. 10
    10. 11
    11. 12
    12. [root@centos79-3 ~]#

    3.3.显示a.txt/b.txt文件的最后5行内容,并显示分开文件名

    命令:

    tail -v -n 5 a.txt b.txt

    1. [root@centos79-3 ~]# tail -v -n 5 a.txt b.txt
    2. ==> a.txt <==
    3. 8
    4. 9
    5. 10
    6. 11
    7. 12
    8. ==> b.txt <==
    9. 8
    10. 9
    11. 10
    12. 11
    13. 12
    14. [root@centos79-3 ~]#

    3.4.实时读取/var/log/messages文件内容

    命令:

    tail -f /var/log/messages

    1. [root@centos79-3 ~]# tail -f /var/log/messages
    2. Sep 19 10:05:19 centos79-3 NetworkManager[710]: <info> [1695089119.0694] dhcp4 (ens32): nameserver '192.168.10.2'
    3. Sep 19 10:05:19 centos79-3 NetworkManager[710]: <info> [1695089119.0694] dhcp4 (ens32): domain name 'localdomain'
    4. Sep 19 10:05:19 centos79-3 NetworkManager[710]: <info> [1695089119.0694] dhcp4 (ens32): state changed bound -> bound
    5. Sep 19 10:05:19 centos79-3 dbus[708]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
    6. Sep 19 10:05:19 centos79-3 systemd: Starting Network Manager Script Dispatcher Service...
    7. Sep 19 10:05:19 centos79-3 dhclient[806]: bound to 192.168.10.225 -- renewal in 855 seconds.
    8. Sep 19 10:05:19 centos79-3 dbus[708]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
    9. Sep 19 10:05:19 centos79-3 systemd: Started Network Manager Script Dispatcher Service.
    10. Sep 19 10:05:19 centos79-3 nm-dispatcher: req:1 'dhcp4-change' [ens32]: new request (2 scripts)
    11. Sep 19 10:05:19 centos79-3 nm-dispatcher: req:1 'dhcp4-change' [ens32]: start running ordered scripts...
  • 相关阅读:
    uniapp时间格式化处理
    C++输入输出(I\O)
    Django框架基础
    JAVA 0基础 字符编码
    工控行业各品牌程序扩展格式和软件
    深入理解Nginx~Nginx的命令行控制
    LOAM误差函数、代价函数的雅克比矩阵详细推导,点到线和点到面误差函数求导
    sdkman 安装以及 graalvm安装
    Vue权限控制
    强化学习:从入门到入坑再到拉屎
  • 原文地址:https://blog.csdn.net/z19861216/article/details/133015648