Often you may want to use both the head and tail commands in Bash to view both the first N lines and last N lines of a file.
You can use the following syntax to do so:
(head; tail) < teams.txt
This particular example will return the first 10 and last 10 lines of the file named teams.txt by default.
You can also specify how many lines to return from both the beginning and end of the file:
(head -3; tail -3) < teams.txt
This particular example will return the first 3 and last 3 lines of the file named teams.txt.
Lastly, you can use the echo statement to print a blank line between the first N lines and last N lines of the file:
(head -3; echo; tail -3) < teams.txt
The following example shows how to use this syntax in practice.
Example: How to Display Both Head and Tail of File in Bash
Suppose that we have a file in our current directory named teams.txt that contains the names of various basketball teams.
We can use the cat command to view the contents of this file:

Suppose that we would like to display only the first 3 lines and last 3 lines from this file.
We can use the following syntax to do so:
(head -3; tail -3) < teams.txt
The following screenshot shows how to use this syntax in practice:

Notice that this returns the first 3 lines and last 3 lines from the file.
Note that we can also use the echo statement to print a blank line in the output between the first 3 lines and last 3 lines of the file:
(head -3; echo; tail -3) < teams.txt
The following screenshot shows how to use this syntax in practice:

Notice that this returns the first 3 lines and last 3 lines from the file, separated by a blank line.
Feel free to change the -3 after the head and tail commands to a different number to display a different number of lines from the beginning and end of a file.
Related Tutorials
The following tutorials explain how to perform other common tasks in Bash:
Bash: How to Select Random Lines from a File
Bash: How to Find Common Lines in Two Files
Bash: How to Print Specific Range of Lines from File
