Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use head -n 10 filename to show a file’s first 10 lines, or head -n 20 filename to show its first 20. GNU head prints 10 lines by default, so head filename is also sufficient when you want 10.

Show the first 10 or 20 lines

Run the command in a terminal, replacing filename with the path to your file:

head -n 10 notes.txt
head -n 20 notes.txt

The -n option specifies a line count. GNU Coreutils 9.11 documents 10 lines as the default when you omit it; the examples above make the requested count explicit.

Use head with command output or multiple files

Read from a pipeline

When you do not provide a file operand, GNU head reads standard input. Pipe another command into it to display only that command’s first 10 lines:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
some_command | head -n 10

You can also use - as a file operand to read standard input.

Display the beginnings of several files

head -n 10 file1.txt file2.txt

With multiple files, GNU head prints a filename header before each file’s output. Use -q (or --quiet) to suppress those headers, or -v (or --verbose) to force them.

Choose lines rather than bytes

For the first 10 or 20 lines, use -n COUNT or GNU’s --lines=COUNT. The -c COUNT or --bytes=COUNT option instead outputs a number of bytes, which may stop partway through a line. GNU also documents size suffixes for byte counts, but flags and details beyond these basic forms can differ across Unix-like implementations.

Use portable syntax in scripts

Prefer head -n 10 file over the older head -10 file form. GNU’s manual describes the leading-count form as obsolete and recommends the explicit -n or -c options for scripts. If a script depends on less common flags or GNU-specific behavior, check the target system’s local head manual; GNU Coreutils 9.11 documentation does not establish that every BSD, BusyBox, or other Unix-like version behaves identically.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Additional GNU options

  • -n -COUNT outputs all but the final COUNT lines in GNU head; verify this behavior on the target system before relying on it outside GNU environments.
  • -z (or --zero-terminated) treats NUL bytes, rather than newline characters, as item separators. GNU documents it for use with NUL-aware tools such as find -print0 and xargs -0.
  • GNU head returns a zero exit status on success and a nonzero status on failure.

These options are documented in the GNU Coreutils 9.11 manual for head. The GNU project manual landing page reports an update date of April 20, 2026; consult the manual installed on your system when implementation-specific behavior matters.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.