LinuxCommandLibrary

head

Display the beginning of a file

TLDR

Output the first few lines of a file

$ head -n [count] [path/to/file]
copy

SYNOPSIS

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

PARAMETERS

-n, --lines=[-]NUM
    Output the first NUM lines instead of the first 10; with the leading '-', print all but the last NUM lines of each file.

-c, --bytes=[-]NUM
    Output the first NUM bytes; likewise with the leading '-'.

-q, --quiet, --silent
    Never print headers giving file names.

-v, --verbose
    Always print headers giving file names.

-z, --zero-terminated
    Line delimiter is NUL, not newline.

DESCRIPTION

The head command in Linux is a utility used to display the first part of a file. By default, it shows the first 10 lines of each specified file to standard output. head is incredibly useful for quickly examining a file's structure, checking configuration settings, or previewing data without needing to open the entire file in a text editor. It's a simple yet powerful command frequently used in shell scripts and command-line workflows, often piped with other commands to extract specific information. The number of lines shown can be customized, and head can also be used with multiple files simultaneously, prefixing each output with the filename. head helps to see the begining of a text file.

MULTIPLE FILES

When using head with multiple files, it prefixes the output of each file with a header indicating the filename unless the -q or --quiet option is specified.

PIPING

head is often used in conjunction with pipes (|) to process the output of other commands. For example, ls -l | head -n 5 would display the first five lines of the output of the ls -l command.

HISTORY

The head command has been a standard utility in Unix-like operating systems for many years. It originated as a simple tool for viewing the initial lines of a file and has remained a consistent part of the Unix toolkit due to its efficiency and ease of use. Its functionality has been standardized across different Unix and Linux distributions, making it a reliable command in various environments. head is part of the GNU coreutils package.

SEE ALSO

tail(1), cat(1), less(1)

Copied to clipboard