When to use head
Use head to inspect the beginning of a text file or stream. This is useful for checking headers and input structure before processing an entire log or exported report.
Syntax
head [OPTIONS] [FILE...]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Show start of log
head -n 20 ./app.logOnly the first twenty lines of the log are printed.
Show start of multiple files
head -n 5 ./one.txt ./two.txtThe first five lines of each file are shown, normally with filename headings.
Read first 128 bytes
head -c 128 ./sample.txtOnly the first 128 bytes are read for display, which may split a multibyte character.
Notes and limitations
- The first ten lines are displayed without parameters.
- Byte reading can truncate a multi-byte character; for text usually use -n.
Common questions and troubleshooting
Does head modify the source?
No. It reads input and writes selected content to standard output unless you separately redirect that output.
Why does a pipeline report a broken pipe?
Once head has enough input it can close the pipe. An upstream process may then receive a broken-pipe signal; interpret this in the context of the pipeline.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man head.