15 C
Texas
angeloma
Senior Writer and partner

The Linux head command

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.

- Advertisement -

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

1.- The head command
1.- The head command

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.

2.- Example file
2.- Example file

option. For example, display the first 3 lines of the file.

:~$ head -n 3 example.txt

3.- Using the Linux head command
3.- Using the Linux head command

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

4.- Using -c option on the head command
4.- Using -c option on the head command

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

5.- Verbose mode
5.- Verbose mode

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.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article