The head command allows you to take a look at the first few lines of a file:

head [FILE]

Here is an example:

image showing basic use of head

We can see the first 10 lines of the file linhas.txt. This is the default behaviour of the head command.

If it is desired to read a number of lines other than 10, the -n option can be used to specify the number of lines to output:

image showing head with -n option

Using -n 5 option, head displays only the first 5 lines from the file.

Learn more.

Most of modern Linux distributions allows you to omit the n when using the -n option.

For example:

image showing head with -NUMBER option

Notice that head -5 has the same effect of head -n 5.

How to read a file skipping the last few lines.

If we place a - just before the number when using -n option, head will print all but the last N lines of the file:

image showing head with -n option for excluding the last lines

The previous command head -n -5 returned 15 of the 20 lines of linhas.txt. In other words, head displayed all but the last 5 lines of the file.