What command displays the first 10 lines of a file in Linux?

The story behind the answer

The Linux command that displays the first 10 lines of a file is `head`. With no line-count option, `head` reads from a named file or standard input and sends the beginning of the data to standard output.

For example, `head report.txt` shows the first ten lines of `report.txt`. The number is configurable: `head -n 20 report.txt` displays the first 20 lines, while `head -c 100 report.txt` displays the first 100 bytes. Because it accepts standard input, `head` is also useful in pipelines, such as `long_command | head` to preview initial output.

The most common mix-up is with `tail`, which displays the end of a file rather than its beginning. `cat` displays the entire file, and `less` opens an interactive pager for browsing rather than selecting the first ten lines by default. Interestingly, some early Unix versions did not include `head`; documentation sometimes used `sed 5q` to print an initial section instead. Modern Unix-like systems commonly provide `head` through GNU Coreutils or their platform’s standard utilities.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: