鍍金池/ 教程/ Linux/ tail命令
which命令
ss命令
cp命令使用示例
ps命令
find命令
grep命令
scp命令
rmdir命令
df命令示例
less命令
du命令示例
chown命令示例
route命令
ping命令
more命令
mv命令
ln命令
mkdir命令
rm命令
find命令常用參數(shù)示例
cat命令
find命令-xargs參數(shù)
touch命令
traceroute命令
gzip命令示例
date命令
ls命令
vmstat命令
lsof命令
diff命令
head命令
watch命令
ifconfig命令
cd命令
tail命令
iostat命令
chgrp命令示例
free命令
find命令-exec參數(shù)
tar命令打包解壓示例
cal命令
at命令
netstat命令
wc命令
chmod命令示例
pwd命令
top命令詳解示例
crontab命令(Linux定時(shí)任務(wù))
whereis命令
Linux命令大全教程
nl命令
rcp命令
locate命令

tail命令

tail 命令從指定點(diǎn)開始將文件寫到標(biāo)準(zhǔn)輸出。使用tail命令的-f選項(xiàng)可以方便的查閱正在改變的日志文件,tail -f filename會(huì)把filename里最尾部的內(nèi)容顯示在屏幕上,并且不但刷新,以便看到最新的文件內(nèi)容。

1.命令格式

tail[必要參數(shù)][選擇參數(shù)][文件]

2.命令功能

用于顯示指定文件末尾內(nèi)容,不指定文件時(shí),作為輸入信息進(jìn)行處理。常用查看日志文件。

3.命令參數(shù)

  • -f 循環(huán)讀取
  • -q 不顯示處理信息
  • -v 顯示詳細(xì)的處理信息
  • -c<數(shù)目> 顯示的字節(jié)數(shù)
  • -n<行數(shù)> 顯示行數(shù)
  • --pid=PID-f合用,表示在進(jìn)程ID,PID死掉之后結(jié)束。
  • -q, --quiet, --silent 從不輸出給出文件名的首部。
  • -s, --sleep-interval=S-f合用,表示在每次反復(fù)的間隔休眠S秒

4.使用實(shí)例

實(shí)例1:顯示文件末尾內(nèi)容

命令:

tail -n 5 log.log

演示執(zhí)行及輸出:

[yiibai@localhost test]$ tail -n 5 log.log
this is line 20.
this is line 21.
this is line 22.

-----------------end
[yiibai@localhost test]$

說(shuō)明:顯示文件最后5行內(nèi)容

實(shí)例2:循環(huán)查看文件內(nèi)容

命令:

tail -f ping.log

演示執(zhí)行及輸出:

[yiibai@localhost test]$ ping www.baidu.com > ping.log &
[1] 2382
[yiibai@localhost test]$ tail -f ping.log
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=9 ttl=57 time=13.1 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=10 ttl=57 time=14.7 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=11 ttl=57 time=13.0 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=12 ttl=57 time=16.0 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=13 ttl=57 time=12.9 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=14 ttl=57 time=14.5 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=15 ttl=57 time=13.2 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=16 ttl=57 time=13.3 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=17 ttl=57 time=12.9 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=18 ttl=57 time=13.2 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=19 ttl=57 time=12.8 ms

64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=20 ttl=57 time=12.4 ms

64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=21 ttl=57 time=11.7 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=22 ttl=57 time=13.1 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=23 ttl=57 time=12.5 ms
^C
[yiibai@localhost test]$

說(shuō)明:ping www.baidu.com > ping.log &,在后臺(tái)ping遠(yuǎn)程主機(jī)。并輸出文件到ping.log;這種做法也使用于一個(gè)以上的檔案監(jiān)視。用Ctrl+c來(lái)終止。

實(shí)例3:從第10行開始顯示文件

命令:

tail -n +10 log.log

演示執(zhí)行及輸出:

[yiibai@localhost test]$ tail -n +10 log.log
this is line 8.
this is line 9.
this is line 10.
this is line 11.
this is line 12.
this is line 13.
this is line 14.
this is line 15.
this is line 16.
this is line 17.
this is line 18.
this is line 19.
this is line 20.
this is line 21.
this is line 22.

-----------------end
[yiibai@localhost test]$

上一篇:netstat命令下一篇:ifconfig命令