The Linux head command

Windows Articles

How to install Screaming Frog SEO Spider on Ubuntu 20.04 / 18.04?

If you are working with blogs and content creation then you should know about SEO. Or in the best case, you have...

How to Configure a Firewall in Ubuntu 20.04 / Debian 10?

There is nothing safe from hackers on the Internet, however, we can implement security measures to be more protected against an attack. With this...

Gnome 3.38 available

Gnome OS is a Linux-based operating system, which has a huge domain in the Linux forums. On September 16, 2020, developers announced...

NVIDIA acquires ARM for $40 billion

Various rumors of an agreement between NVIDIA and SoftBank to acquire Arm. Where NVIDIA announces that they reached an agreement to buy...

How to install CodoForum on Ubuntu 20.04 / Debian 10?

Hi, folks. In this post, I will show you how to install CodoForum in Ubuntu 20.04 /Debian 10. This program is quite useful to...
angeloma
angeloma
Senior Writer and partner

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

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.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install Screaming Frog SEO Spider on Ubuntu 20.04 / 18.04?

If you are working with blogs and content creation then you should know about SEO. Or in the best case, you have...

How to Configure a Firewall in Ubuntu 20.04 / Debian 10?

There is nothing safe from hackers on the Internet, however, we can implement security measures to be more protected against an attack. With this...

Gnome 3.38 available

Gnome OS is a Linux-based operating system, which has a huge domain in the Linux forums. On September 16, 2020, developers announced...

NVIDIA acquires ARM for $40 billion

Various rumors of an agreement between NVIDIA and SoftBank to acquire Arm. Where NVIDIA announces that they reached an agreement to buy...

How to install CodoForum on Ubuntu 20.04 / Debian 10?

Hi, folks. In this post, I will show you how to install CodoForum in Ubuntu 20.04 /Debian 10. This program is quite useful to...
x