tail 显示文件内容尾部
1.命令功能
tail默认显示文件内容尾部10行。
2.语法格式
tail option file
参数说明
参数 |
参数说明 |
-n |
显示指定行数 |
-f |
实时输出文件变化后追加的数据 |
-s |
监视文件变化的间隔秒数 |
-v |
总是显示包含指定文件名的文件头 |
3.使用范例
范例1 tail 默认显示后10行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [root@localhost chu] # tail passwd nobody:x:99:99:Nobody:/: /sbin/nologin vcsa:x:69:69:virtual console memory owner: /dev : /sbin/nologin saslauth:x:499:76:Saslauthd user: /var/empty/saslauth : /sbin/nologin postfix:x:89:89:: /var/spool/postfix : /sbin/nologin sshd:x:74:74:Privilege-separated SSH: /var/empty/sshd : /sbin/nologin ntp:x:38:38:: /etc/ntp : /sbin/nologin cxf:x:500:500:: /home/cxf : /bin/bash ok:x:501:501:: /home/ok : /bin/bash joe:x:502:502:: /home/joe : /bin/bash chu:x:503:503:: /home/chu : /bin/bash |
范例2 实时监控文件变化追加的内容
1 2 3 4 5 6 7 8 9 10 11 | [root@localhost chu] # tail -f /var/log/messages Apr 23 14:47:22 localhost sshd[1309]: Server listening on :: port 22. Apr 23 14:47:22 localhost xinetd[1320]: xinetd Version 2.3.14 started with libwrap loadavg labeled-networking options compiled in . Apr 23 14:47:22 localhost xinetd[1320]: Started working: 1 available service Apr 23 14:47:24 localhost sshd[1436]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use. Apr 23 14:47:24 localhost sshd[1436]: error: Bind to port 22 on :: failed: Address already in use. |
范例3 显示文件头部
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@localhost chu] # tail -vf /var/log/messages ==> /var/log/messages <== Apr 23 14:47:22 localhost sshd[1309]: Server listening on :: port 22. Apr 23 14:47:22 localhost xinetd[1320]: xinetd Version 2.3.14 started with libwrap loadavg labeled-networking options compiled in . Apr 23 14:47:22 localhost xinetd[1320]: Started working: 1 available service Apr 23 14:47:24 localhost sshd[1436]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use. Apr 23 14:47:24 localhost sshd[1436]: error: Bind to port 22 on :: failed: Address already in use. |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步