Head command in linux/Unix

Head command in linux/Unix

Head command prints N number of lines from a file. By default head command will print the top 10 lines of a file. Head command is part of text processing commands. Head command is one of the linux basics and most used commands.

Head command in linux/Unix

 

How to use head command

#head /etc/passwd

The above example displays top ten lines of the file /etc/passd

 

To view first 20 lines of file using head command

#cat /etc/passwd | head -n 20

Head command in linux/Unix

or

#head -n 20 /etc/passwd

Option:

-n — Prints the first N numbers. If 30 mentioned instead of n, then first 30 lines of a file will be printed

 

To view first 30 lines of a file using head command

#cat /etc/passwd | head -30

Another Method

#head -30 /etc/passwd

 




Leave a Reply

Your email address will not be published. Required fields are marked *