1. 程式人生 > >tail 顯示文件內容尾部

tail 顯示文件內容尾部

rtu listening eight AD sla 頭部 -a AS add

1.命令功能

tail默認顯示文件內容尾部10行。

2.語法格式

tail option file

參數說明

參數

參數說明

-n

顯示指定行數

-f

實時輸出文件變化後追加的數據

-s

監視文件變化的間隔秒數

-v

總是顯示包含指定文件名的文件頭

3.使用範例

範例1 tail 默認顯示後10行

[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 實時監控文件變化追加的內容

[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 顯示文件頭部

[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.

tail 顯示文件內容尾部