Linux head command description.

The system of Linux head command displays the starting of a file. It is by default, displays starting 10 lines of any file.

Syntax of head command :

# head <file name>

Like example of head command :

# head ‘newdoc’

Look at the above snapshot, command “head newdoc” has displayed the first ten lines of the file ‘doc’.

Head command for multiple files

If we’ll write two file names then it will display first ten lines (in this case file has 5 lines only) of each file separated by a heading.

Sample syntax like :

# head <file name> <file name>

like example of command head :

Look at the above, content of both the files are displayed with a separate heading with the help of “head newdoc doc” command. Here newdoc and doc is file.

Linux head -n command

The Unix and Linux head -n option displays specified number of lines.

Sample syntax of head -n below :

# head -n <file name> [ n means line number ]

like example line number command :

# head -5 newdoc

Look at the above snapshot, 5 lines are displayed by the command “head -5 newdoc”.

The above example syntax can also be written as “head -n5 newdoc” or “head -n 5 newdoc”. In all cases result will be same.

Linux head -c command

System of Linux head -c command counts the number of bytes of a file.

Sample syntax of head-c command :

# head -c <number> <file name>

Like example of head-c command :

# head -c 25 newdoc

Look at the above, 20 byte content of file ‘newdoc’ is display with the help of command “head -c 20 newdoc”.

Here: Bytes counting has only one syntax unlike lines counting.

If you will use “head -ck “then it will return the result by multiplying the number by suffix. That is also can be “b (bytes=512), k(kilobytes=1024) and m (megabytes=1048576)”.

Now you can practice head command with your shell on your ability. Thank you 🙂 .

Leave a Reply