Site icon LinuxCommands.site

head command tutorial in linux/unix with examples and use cases

Linux head command – output the first part of files.

Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.

syntax

head [OPTION]... [FILE]...

options

examples

Print top 10 lines of file

➜  ~ head /etc/passwd

Print file header specifies the number of lines – head -n

➜  ~ head -n 3 /etc/passwd

Print multiple file information

➜  ~ head -v /etc/passwd /etc/group

OR

➜  ~ head -v -n 10 /etc/passwd /etc/group

head offset – print 2 to 10 lines of the file

➜  ~ tail +2 /etc/passwd | head -9

linux head skip first line

Use the tail command (tail +n), from line 2 to the end of the file

➜  ~ tail +2 /etc/passwd 

Exit mobile version