head和tail就像它们的名字同样浅显易懂,head头部,用于显示文件开头或者指定的区域,head用于获取文件开头信息至标准输出,而tail则是用于获取文件尾部信息至标准输出。
linux
命令格式:bash
head [option] filenameide
命令参数:spa
-c :指定显示的字符数。
ci
-n :指定显示的行数,不指定-n默认显示文件前10行。
it
-q :隐藏文件名称。
io
-v :显示文件名。
class
命令实例:test
显示文件前10行。file
命令:head test.txt #不加参数,默认输出文件头10行。
输出:
[root@oldboylinux ~]# head test.txt 1 2 3 4 5 6 7 8 9 10 [root@oldboylinux ~]#
2.显示文件头15行。
命令:head -n 15 test.txt
输出:
[root@oldboylinux ~]# head -n 15 test.txt 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [root@oldboylinux ~]#
3.显示文件的头20个字符
命令:head -c 20 test.txt
输出: #每行行尾存在一个换行符,能够在vi命令模式下,说用set list看到。
[root@oldboylinux ~]# head -c 20 test.txt 1 2 3 4 5 6 7 8 9 10[root@oldboylinux ~]#