码迷,mamicode.com
首页 > 其他好文 > 详细

head&&tail

时间:2017-07-29 18:57:39      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:art   space   shel   color   打印   脚本   rac   hit   gre   

//參考《Linux shell脚本攻略 第2版》

1,head

a)打印前10行:

ubuntu@VM-62-13-ubuntu:~$ head file


b)打印前5行:

ubuntu@VM-62-13-ubuntu:~$ head-n 5 file 或者ubuntu@VM-62-13-ubuntu:~$ head-5 file 


c)打印除了最后M行之外的全部行:

ubuntu@VM-62-13-ubuntu:~$ head-n -M file


2,tail

a)打印文件的最后10行:

ubuntu@VM-62-13-ubuntu:~$tail file


b)打印最后5行:

ubuntu@VM-62-13-ubuntu:~$tail-n 5 file 或者ubuntu@VM-62-13-ubuntu:~$tail -5 file 


c)打印除了前M行之外的全部行:

ubuntu@VM-62-13-ubuntu:~$tail -n +(M+1) file

d) tail -f 能够密切关注文件里新添加的内容,并随着数据的添加持续保持更新,当中能够加上一个睡眠间隔 -s。这样我们能够设置监视文件的时间间隔(假设进行Fun一直向监控的文件追加数据,则tail -f 就会一直运行知道进程Fun结束):

pgrep Fun | xargs tail -f  file -s 20 --pid

pidof Fun | xargs tail -f file -s 20 --pid

head&&tail

标签:art   space   shel   color   打印   脚本   rac   hit   gre   

原文地址:http://www.cnblogs.com/wzzkaifa/p/7256977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!