简介
head命令将一个或多个文件或管道数据(默认为10行)打印到标准输出。
命令格式
head [OPTION]… [FILE]…
常用参数
| -n [-]K | 显示前K行。如果K前有-,则表示显示除最后K行外的所有行 |
|---|---|
| -c [-]K | 显示文件前K字节。如果K前有-,则表示显示除最后K字节外的所有内容 可以在数字后面使用乘数后缀来指定要显示的字节数。 **b**乘以512,**kB**乘以1000,**K**乘以1024,**MB**乘以1000000,**M**乘以1048576 |
| -v | 显示文件名称 |
| -q | 不显示文件名 |
示例
[root@localhost ~]# cut -d ':' -f 1 /etc/passwd | head -n 11 > test.txt[root@localhost ~]# cat test.txtrootbindaemonadmlpsyncshutdownhaltoperatorgames[root@localhost ~]# wc test.txt11 11 62 test.txt## -n 显示多少行 默认显示 10 行[root@localhost ~]# head -n 10 test.txtrootbindaemonadmlpsyncshutdownhaltoperator[root@localhost ~]# head -n -10 test.txtroot## -c 显示多少字节[root@localhost ~]# head -c 4 test.txtroot[root@localhost ~]#[root@localhost ~]# head -c -58 test.txt ## -58字节root[root@localhost ~]### -v 显示文件名称[root@localhost ~]# head -n 1 -v test.txt==> test.txt <==root## -q 不显示文件名[root@localhost ~]# head -n 1 -q test.txtroot
