head, tail, more & less Commands in Unix/Linux

head : to display specified number of lines from top of the file.

——–

head cities.txt

 

* Display 10 lines from top of the file.

* 10 is the dfault value for head command

 

head -n 15 cities.txt  (or)  head -15 cities.txt

 

head -n 5 cities.txt  

 

 

tail : to display specified number of lines from bottom of the file.

—————-

tail cities.txt

 

* Display  last 10 lines from the file.

* 10 is the dfault value for tail command

 

tail -n 15 cities.txt  (or)  tail -15 cities.txt

 

tail -n 5 cities.txt   

 

 

Display the lines from 10 to 15 ?

head -15 cities.txt | tail -6

 

Display the lines from 20 to 30 ?

head -30 cities.txt | tail -11

 

ls – l   Display List of files and directories

 

ls -l | head -5   Display Top 5 files and directories

ls -l | tail -5   Display Top 5 files and directories

 

 

more : Display content page by page.(Next page – space, Next line – Enter,  q- Command prompt)

————–

more cities.txt

 

more : Display content page by page in both directions means next page or to previos page

Next page – space, Next line – Enter,  q- Command prompt)

————–

more cities.txt

ls -l | more

ls -l | less

Leave a Reply

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