head command (Linux / bash / sh / zsh)
What it does
Print the beginning of files or standard input. When people search for the head command linux lines, they usually want head's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.
Print the beginning of files or standard input.
Syntax
head [OPTION]... [FILE]...
Common options
| Flag / option | Meaning |
|---|---|
| -n N | Print the first N lines. |
| -c N | Print the first N bytes. |
| -q | Suppress file-name headers. |
| -v | Always print file-name headers. |
Practical examples
First ten lines
head app.log
Prints the default ten lines.
CSV header
head -n 1 data.csv
Prints only the first row.
Preview bytes
head -c 64 binary.dat | xxd
Feeds the first 64 bytes to a hex viewer.
Common mistakes
- Assuming `-c` counts characters; it counts bytes.
- Using head as a safe parser for multiline structured records.
Related commands
- tailPrint the end of input and optionally follow appended data.
- catConcatenate files and write their contents to standard output.
- lessPage through text interactively without loading it all at once.
- grepSearch text for lines matching a pattern.
- Where-ObjectFilter pipeline objects by property values or a script block predicate.
- Get-ContentRead file content or provider data as a stream of objects.
- echoWrite arguments and shell-expanded values to standard output.
- echoDisplay text or control command echoing in a batch script.
FAQ
What does head do in Linux?
Print the beginning of files or standard input.
How do I use head from the terminal?
Start with `head [OPTION]... [FILE]...`, then choose only the options needed for the task.
What is a practical head example?
Try `head app.log` — Prints the default ten lines.
Can I use head in a shell script?
Yes. head works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.