Linux中head与tail命令结合用法
Linux命令:显示文件头尾
Head/Tail
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然就是看档案的结尾,看看下面的范例:
注意:一般我们在查看/etc/passwd或者group等时,由于行号过多,眼花缭乱,故可用cat -n来显示行号。
1
1)显示/etc/passwd的前 6 行:head -6 /etc/passwd
2)显示/etc/passwd最后的 25 行:tail
3)结合了 head 与 tail 的指令,显示/etc/passwd的第 11 行到第 20 行:head -20 /etc/passwd |tail -10
//显示头的20行且从最后10个开始显示
4)把/etc/passwd文件的5-12行内容中包含有”sbin”字符串的行显示在屏幕上:
[[email protected]/etc]$ head -12 /etc/passwd |tail -8 |grep 'sbin’
//12-5+1=8 tail -8