Linux 读取文件:head 命令(前 10 行)
head 命令显示一个文件开头的内容。默认显示文件的前十行。
语法:
head <file name>
例子:
head jtp.txt
上面的截图,"head jtp.txt" 显示 "jtp.txt"的前十行。
Head 命令带多个文件
如果我们写了两个文件的名字,它会显示每个文件的开头十行内容,用一个标题来分隔。
语法:
head <file name> <file name>
例子:
head doc1.txt doc2.txt
看上面的截图,"head doc1.txt doc2.txt" 命令显示了两个文件的内容并用标题来分隔。
Linux head -n
head -n
选项显示指定的行数。
Syntax:
head -n <file name>
Example:
head -15 jtp.txt
如图, head -15 jtp.txt
显示文件中前15行。
Note: 上面的例子也可以写作 head -n15 jtp.txt
或 head -n 15 jtp.txt
结果都是一样的。
Linux head -c
head -c
显示文件的前多少个字节的内容。
Syntax:
head -c <number> <file name>
Example:
head -c 20 jtp.txt
如图, head -c 20 jtp.txt
显示了 jtp.txt
前20个字节的内容。
Note: 按字节显示只有这一种语法不像 -n
选项.
如果你使用 head -c<number>k <file name>
它会返回由后缀乘 number 个字符。 后缀可以是 "b (bytes=512), k(kilobytes=1024) 和 m (megabytes=1048576)"。