Linux head command with examples

In this article, we will learn Linux head command with examples step by step.

Linux head command is used to print first few lines of a file. By default, it prints first 10 lines of a file on terminal.

Linux head command Syntax:

head [option] file_name

Linux head command options:

-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 --help display this help and exit --version output version information and exit NUM may have a multiplier suffix: b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

Linux head command examples:

1. View first 10 lines of a file.

head more.txt

Linx head command with examples

2. To view first 20 lines of a file.

head -20 less.txt more.txt

3. To view first 100 bytes of a file.

head -c 100 more.txt

4. To print 5000 lines of file in Linux.

head -5k more.txt

5. To print first 10 megabytes of a file.

head -c 10M more.txt

6. To print first 20 lines of more than one file.

head -20 more.txt less.txt