Back to the command reference

head

FilesBeginner In simulator In real Linux

Print the first lines of files

Name: head

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

head prints the first part of each file, 10 lines by default. With several files, each gets a ==> name <== header.

It often ends a pipeline to keep just the top results, as in sort ... | head.

Syntax

head [OPTION]... [FILE]...

Common options

-n / --lines [-]NUMShow the first N lines (default 10); -5 also works
-c / --bytes [-]NUMShow the first N bytes
-q / --quietWith several files, leave out the name headers
-v / --verboseAlways show the name headers

Examples

  • $ head -n 3 logs/app.log

    First 3 lines of the log

    Explain
  • $ ls /usr/bin | head

    Only the first 10 entries of a listing

    Explain

Related