Hi, folks. We’re still exploring the terminal and this time we’re going to focus on the Linux head command. So let’s go for it.
If you’re new to Linux you probably won’t like the terminal, and that’s understandable but I’m also telling you that it’s a very powerful tool and it’s not as complicated as it seems. Also, many sysadmin users use it almost every day and this is because it is very efficient.
Yes, it is true, there are more complicated commands to use but in this case, the head command is quite simple.
Introduction
The head command is the complement of the Tail command. It is used to display the first few lines of a text file. Therefore, the use of this command is very useful for sysadmin that needs to check logs constantly.
Like the Tail command, the head command belongs to GNU utils which is a range of tools for processing files and folders by the terminal. So this command is for sure available in your favorite Linux distribution.
Now we will show you how to use it with some simple examples.
Using the Linux Head command
The Head command is one of the simplest there is. The basic syntax of the command is as follows:
~$ head [OPTION]... [FILE]..
As you can see there are options that alter the behavior of the command. To see all the available options, just use this command:
:~$ head --help
And as you can see in the image, they are few and this reaffirms what I said about it being a pretty simple command to use.
To better demonstrate the use of the command, I have created a text file called example.txt and added certain names.
option. For example, display the first 3 lines of the file.
:~$ head -n 3 example.txt
We can even use the head command to display a number of bits of the file. This is made possible by the -c option.
:~$ head -c 10 example.txt
Finally, it is possible to use the -v option to display the title of the file. Use it in some cases.
:~$ head -v example.txt
And well, that’s it. The head command is quite useful and simple to use and using it with the tail command makes an extraordinary combination.
Please, share this post and join our Telegram channel.