The Linux head command

Windows Articles

How To Configure Slave BIND DNS Server On Ubuntu 20.04

In our previous guide we covered the setup of Master(Primary) DNS Server. Here we'll learn that how to configure slave bind dns server on...

Install Fossil on Linux – An alternative to Git

Hello, friends. In this post, we will talk about a serious alternative to Git. In a few words, we'll show you how to install...

How to backup and restore BCD in Windows 10

Hi! Boot Configuration Data (BCD) is a set of data where the system boot information is stored. In addition, from there the operating systems...

How To Install and Configure Master BIND DNS Server On Ubuntu 20.04

Today we are going to learn that how to install and configure Master BIND DNS server on Ubuntu 20.04. As you all know that...

Diskpart is a very useful tool for managing storage in Windows 10.

Hello! Diskpart is an internal tool included in Windows systems that allows you to manage storage units. Indeed, it is possible to manage internal...
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 Configure Slave BIND DNS Server On Ubuntu 20.04

In our previous guide we covered the setup of Master(Primary) DNS Server. Here we'll learn that how to configure slave bind dns server on...

Install Fossil on Linux – An alternative to Git

Hello, friends. In this post, we will talk about a serious alternative to Git. In a few words, we'll show you how to install...

How to backup and restore BCD in Windows 10

Hi! Boot Configuration Data (BCD) is a set of data where the system boot information is stored. In addition, from there the operating systems...

How To Install and Configure Master BIND DNS Server On Ubuntu 20.04

Today we are going to learn that how to install and configure Master BIND DNS server on Ubuntu 20.04. As you all know that...

Diskpart is a very useful tool for managing storage in Windows 10.

Hello! Diskpart is an internal tool included in Windows systems that allows you to manage storage units. Indeed, it is possible to manage internal...
x