There are several commands and programs provided by Linux for viewing the contents of file. Working with files is one of the daunting task, most of the computer users be it newbie, regular user, advanced user, developer, admin, etc performs. Working with files effectively and efficiently is an art.

Today, in this article we will be discussing the most popular commands called head, tail and cat, most of us already aware of such commands, but very few of us implement it when needed.

1. head Command

The head command reads the first ten lines of a any given file name. The basic syntax of head command is:

head [options] [file(s)]

For example, the following command will display the first ten lines of the file named ‘/etc/passwd‘.

If it is desired to retrieve more number of lines than the default ten, then ‘-n‘ option is used along with an integer telling the number of lines to be retrieved. For example, the following command will display first 5 lines from the file ‘/var/log/yum.log‘ file.

The head command can also display any desired number of bytes using ‘-c‘ option followed by the number of bytes to be displayed. For example, the following command will display the first 45 bytes of given file.

That’s all for now. I’ll be here again with another Interesting Article, worth Knowing. Till then stay tuned and connected to Tecmint. Don’t forget to provide us with your valuable feedback in our comment section.