1. head 命令说明
head:用来显示文件开头,默认10行,基本信息如下:
DESCRIPTION
Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.
head [OPTION]... [FILE]...
DESCRIPTION
Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=[-]K
print the first K bytes of each file; with the leading ‘-’, print all but the last K bytes of each file
-n, --lines=[-]K
print the first K lines instead of the first 10; with the leading ‘-’, print all but the last K lines of each file
-q, --quiet, --silent
never print headers giving file names
-v, --verbose
always print headers giving file names
--help display this help and exit
--version
output version information and exit
参数如下:
选项 | 作用 |
---|---|
-c | 显示文件前几个字节内容 |
-n | 显示文件前几行内容 |
-q | 不显示文件名 |
-v | 显示文件名 |
2. head 命令语法
head [选项] fileName
3. head 命令示例
3.1 不加参数
head fileName
3.2 -c(按照字节显示)
-c 后面跟数值,表示要显示的字节数,utf-8 字符集时,一个中文三个字节,空格、换行符算一个字节。
head -c num fileName
如果 -c 后面是 -num,则是显示除了最后 num 个字节外的内容。
举例:显示除了最后5个字节的内容
head -c -5 fileName
3.3 -n(按照行数显示)
类似 -c ,-n 后面也是数值,代表需要显示的行数,若为负数,则是显示除了后面行数的内容。
另外,head 后面直接加 -num 也可以达到显示前 num 行内容的效果。
head -n num fileName
3.4 -v(显示文件名)
-q:不显示文件名,-v:显示文件名,在 head 多个文件时有用。
head -v fileName1 fileName2
4. 总结
head 可显示文件开头内容。