tail 显示文件内容尾部

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.
posted @ 2018-04-25 21:41  joe.chu  阅读(917)  评论(0编辑  收藏  举报