The head
command in Linux is used to display the beginning of a file, typically the first 10 lines. It is especially useful for quickly viewing the contents of large files without opening the entire file. By default, head
shows the first 10 lines, but this can be adjusted using various options.
Basic Syntax:
head [OPTION]… [FILE]…
Common Options:
-n NUMBER
or--lines=NUMBER
: Display the first NUMBER lines instead of the default 10.-c NUMBER
or--bytes=NUMBER
: Display the first NUMBER bytes.-q
or--quiet
: Never print headers giving file names.-v
or--verbose
: Always print headers giving file names.-z
or--zero-terminated
: Line delimiter is NUL, not newline.
Examples:
- Display the first 10 lines of a file (default behavior)

2. Display the first 50 bytes of a file:

3. Display the first lines of multiple files:

Practical Uses:
- Quickly peek at the beginning of large files
- View file headers or initial content
- Limit output of other commands when piped
- Check the structure or format of data files
The head
command is particularly useful when you need to quickly inspect the beginning of files or limit the amount of output from other commands. It’s often used in scripts and in combination with other commands to process or analyze data.