文本处理命令系列――head和tail
2015-11-09 11:24
495 查看
head:查看文件的内容,默认显示的是前10行内容。
tail:查看文件的内容,默认显示的是后10行内容。
head和tail如果想显示指定行数的内容,可以用-n选项。
示例:
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 ~]#本文出自 “Felix Zhang” 博客,请务必保留此出处http://hezhanglinux.blog.51cto.com/10861477/1710965
相关文章推荐
- http://blog.csdn.net/altair86/article/details/8972178
- Paint.Join与Paint.Cap
- 利用AIDL来实现由Binder进行进程间通信(IPC)
- tail 显示文件最后若干行内容
- [LeetCode]66. Factorial Trailing Zeros阶乘的尾零个数
- How do I remap certain keys or devices?
- Paint House II 解答
- Paint House 解答
- Daily Scrum meeting 2015.11.9
- 解读:全国100强企业为何选择TurboMail邮件系统
- weak和Strong,assign和retain和copy的区别
- 【Alpha】Daily Scrum Meeting第六次
- 【Alpha】Daily Scrum Meeting第六次
- Daily Scrum (2015/11/7)
- 【设计模式】Filter-Chain 的应用
- 【小玩意儿:在页面上设置链接发送E-mail】
- [leetcode] 219 Contains Duplicate II(map)
- zabbix设置sendmail发送邮件
- zabbix设置sendmail发送邮件
- Jetbrains的产品对在校学生免费