← 返回命令列表

Linux command

head 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Example

head path/to/file

Example

head -n 5 path/to/file

Example

head -c 100 path/to/file

Example

head -n -5 path/to/file

Example

head path/to/file1 path/to/file2

Example

head -q path/to/file1 path/to/file2

说明

head outputs the first 10 lines of each FILE to standard output. When processing multiple files, it precedes each with a header containing the filename. If no file is specified or when FILE is "-", it reads from standard input.

参数

-c, --bytes=-NUM
Print the first NUM bytes of each file; with leading "-", print all but the last NUM bytes
-n, --lines=-NUM
Print the first NUM lines instead of 10; with leading "-", print all but the last NUM lines
-q, --quiet, --silent
Never print headers giving filenames
-v, --verbose
Always print headers giving filenames
-z, --zero-terminated
Use NUL as line delimiter instead of newline

FAQ

What is the head command used for?

head outputs the first 10 lines of each FILE to standard output. When processing multiple files, it precedes each with a header containing the filename. If no file is specified or when FILE is "-", it reads from standard input.

How do I run a basic head example?

Run `head path/to/file` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --bytes=-NUM do in head?

Print the first NUM bytes of each file; with leading "-", print all but the last NUM bytes