标签:head tail ‘tail -f’ ‘tail -f’
head:查看文件的内容,默认显示的是前10行内容。
tail:查看文件的内容,默认显示的是后10行内容。
head和tail如果想显示指定行数的内容,可以用-n选项。
选项说明: head -n number:显示前number行的内容。 head -c number-bytes:显示前面多少个字节的内容。可以使用K等单位。如head -c 5k显示前5K的内容。 head -n -number:显示除了后面的number行之外的所有行。
tail -n number:显示后面number行的内容。 tail -c number-bytes:显示后面多少个字节的内容。 tail -n +number:从number行以后开始显示所有行的内容。 tail -f filename:持续监视一个文件的内容变化,常用于查看日志文件。 tail -F filename:作用和tail -f一样,但是当一个监视的文件被移走时,tail -F会重试。
示例:
[root@vm1 ~]# cat -n /etc/services | head 1 # /etc/services: 2 # $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $ 3 # 4 # Network services, Internet style 5 # IANA services version: last updated 2009-11-10 6 # 7 # Note that it is presently the policy of IANA to assign a single well-known 8 # port number for both TCP and UDP; hence, most entries here have two entries 9 # even if the protocol doesn‘t support UDP operations. 10 # Updated from RFC 1700, ``Assigned Numbers‘‘ (October 1994). Not all ports [root@vm1 ~]#
[root@vm1 ~]# cat -n /etc/services | tail 10765 nimgtw 48003/udp # Nimbus Gateway 10766 3gpp-cbsp 48049/tcp # 3GPP Cell Broadcast Service Protocol 10767 isnetserv 48128/tcp # Image Systems Network Services 10768 isnetserv 48128/udp # Image Systems Network Services 10769 blp5 48129/tcp # Bloomberg locator 10770 blp5 48129/udp # Bloomberg locator 10771 com-bardac-dw 48556/tcp # com-bardac-dw 10772 com-bardac-dw 48556/udp # com-bardac-dw 10773 iqobject 48619/tcp # iqobject 10774 iqobject 48619/udp # iqobject [root@vm1 ~]#
head -n -number和tail -n +number的用法: [root@vm1 ~]# cat -n /etc/issue | head -n -2 1 CentOS release 6.5 (Final) [root@vm1 ~]# [root@vm1 ~]# cat -n /etc/issue | tail -n +2 2 Kernel \r on an \m 3 [root@vm1 ~]#
本文出自 “热爱开源,乐于分享!” 博客,请务必保留此出处http://hezhanglinux.blog.51cto.com/10861477/1710965
标签:head tail ‘tail -f’ ‘tail -f’
原文地址:http://hezhanglinux.blog.51cto.com/10861477/1710965