Head Command in Linux With Examples
Head Command in Linux With Examples
Syntax:
where,
$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat
Haryana
Himachal Pradesh
Jammu and Kashmir
Jharkhand
Karnataka
Kerala
Madhya Pradesh
Maharashtra
Manipur
Meghalaya
Mizoram
Nagaland
Odisha
Punjab
Rajasthan
Sikkim
Tamil Nadu
Telangana
Tripura
Uttar Pradesh
Uttarakhand
West Bengal
$ cat capital.txt
Hyderabad
Itanagar
Dispur
Patna
Raipur
Panaji
Gandhinagar
Chandigarh
Shimla
Srinagar
Example:
$ head state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat
Haryana
Himachal Pradesh
Jammu and Kashmir
Options
$ head -n 5 state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
$ head -c 6 state.txt
Andhra
$ head -v state.txt
==> state.txt <==
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Goa
Gujarat
Haryana
Himachal Pradesh
Jammu and Kashmir
$ ls -t | head -n 3 | sort
c.txt
d.txt
e.txt
?list=PLqM7alHXFySFc4KtwEZTANgmyJm3NqS_L
Conclusion
The head command in Linux is an essential tool for
quickly viewing the btop lines of files. Whether
you need to display a specific number of lines,
view files in a custom format, or pipe output from
other commands, head command for Linux makes
it easy to manipulate the text files.
head example.txt
head -c 10 filename
head -n 20 filename
head example.txt
Similar Reads
Linux Commands
Linux commands are essential for controlling and managing the system
through the terminal. This terminal is similar to the command prompt in…
Windows. It’s important to note that Linux/Unix commands are case-
15+ min
sensitive. read commands are used for tasks like file handling, process
These
management, user adm
Need to quickly view the beginning of a file in Linux? The head command
is your best option. This essential command-line tool enables users,…
developers, and system administrators to preview the start of log files,
6 min readfiles, CSV datasets, and other text documents in seconds.
configuration
The head comma
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read
Got It !
@GeeksforGeeks, Sanchhaya Education andPrivate
understood our Cookie
Limited, Policy
All rights & Privacy Policy
reserved