head Linux Command Cheatsheet




head Linux Command is used to display beginning of a text file/ piped data.

Syntax

head [options] file-name

Examples

For example consider the following file

$ cat readme.txt 
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
line11
line12
line13
line14
line15
$ head readme.txt
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10 
Note: head by default shows first 10 lines

Showing first 2 lines

$ head -n 2 readme.txt
line1
line2

Showing first 5 lines

$ head -n 5 readme.txt
line1
line2
line3
line4
line5

Showing from multiple files

$ head -n 2 readme.txt readme-2.txt
==> readme.txt <==
line1
line2

==> readme-2.txt <==
line1
line2

Showing from all files that are starting with readme

$ head -n 2 readme*
==> readme-2.txt <==
line1
line2

==> readme-3.txt <==
line1
line2

==> readme.txt <==
line1
line2


┬ęCopyright 2020 OneCompiler | Privacy Policy | Terms & Conditions