head
The command that prints the first lines of its input, ten by default or as many as -n says.
In more detail
In a pipeline, head exits once it has enough lines and the command feeding it is then stopped, which is why seq 1 2000000 | head -3 finishes at once. It is the quick way to peek at the start of a large file.
Examples
head -n 3 poem.txthead -n 1 "$1" reads the subject line of a commit message file.Related terms
- tail — The command that prints the last lines of its input, ten by default or as many as -n says.
- pipe — The | operator, which connects one command's standard output to the next command's standard input so they run together.
Taught in
- Arrays, And Why Dollar At Is Not Dollar Star — Bash Scripting & Command Line Automation
- Redirection: Truncate, Append, Both Streams — Bash Scripting & Command Line Automation
- Pipelines, tee And Process Substitution — Bash Scripting & Command Line Automation
- Archives, Transfers And The Network — Bash Scripting & Command Line Automation
- Scheduling, Monitoring And A Script That Reports — Bash Scripting & Command Line Automation
- A Repository Is A Folder With A Memory — Advanced Git Internals & Distributed Workflows
- Conventional Commits — Advanced Git Internals & Distributed Workflows
- A Branch Is A Moving Pointer — Advanced Git Internals & Distributed Workflows
- HEAD, And Why Detached HEAD Is Not An Error — Advanced Git Internals & Distributed Workflows
- Rebase: The Same Work, A Different History — Advanced Git Internals & Distributed Workflows
- What A Remote Actually Is — Advanced Git Internals & Distributed Workflows
- Interactive Rebase: Squash, Reorder, Reword — Advanced Git Internals & Distributed Workflows