Linux Head Command

the head command in linux os is used to print the first N lines from file to the terminal.by default head command will display first 10 lines from file.

Syntax

$head [option] [file_name]

Opetions

Sr.No

Options

Descriptions

01

-n

it will print the first N lines of the file.with leading "-" it will print all the lines,excepting last N lines from the file.

02

-c

it will print the first N bytes of file.with leading "-" it will print all the bytes skipping the last N bytes of the file.

Example


$head file1.txt
						

display the first 10 lines from file1.txt file



$head -n3 file1.txt
						

display first N lines from a file



$head -n-5 file1.txt
						

display the contents of file by skipping last N lines from a file.



$head -c5 file1.txt
						

display first 5 charaters from file1.txt file



$head -c-7 file1.txt
						

skip the last 7 charaters from linux file



$head -n4 file1.txt file2.txt file3.txt file4.txt
						

display the first 4 line from all file file1.txt,file2.txt,file3.txt,file4.txt

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!