Javatpoint Logo
Javatpoint Logo

Linux head command

The 'head' command displays the starting content of a file. By default, it displays starting 10 lines of any file.

Syntax:

Example:

Linux Head1

Look at the above snapshot, command "head jtp.txt" has displayed the first ten lines of the file 'jtp.txt'.


Head command for multiple files

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

Syntax:

Example:

Linux Head2

Look at the above snapshot, content of both the files are displayed with a separate heading with the help of "head doc1.txt doc2.txt" command.


Linux head -n

The 'head -n' option displays specified number of lines.

Syntax:

Example:

Linux head-n

Look at the above snapshot, 15 lines are displayed by the command "head -15 jtp.txt".

Note: The above example syntax can also be written as "head -n15 jtp.txt" or "head -n 15 jtp.txt". In all cases result will be same.


Linux head -c

The 'head -c' command counts the number of bytes of a file.

Syntax:

Example:

Linux head-c

Look at the above snapshot, 20 byte content of file 'jtp.txt' is displayed with the help of command "head -c 20 jtp.txt".

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

If you'll use "head -c<number>k <file name>"then it will return the result by multiplying the number by suffix. Suffix can be "b (bytes=512), k(kilobytes=1024) and m (megabytes=1048576)".

Next TopicLinux tail




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA