Cheat Sheet #day57 - head
head
Command Cheatsheet
The head
command is used to display the first part of a file or output. It is commonly used to quickly view the beginning of files or outputs, often to check file contents or inspect logs.
Syntax
head [OPTION]... [FILE]...
Common Options
-n NUM
: Output the first NUM lines. Default is 10.-c NUM
: Output the first NUM bytes.-q
: Suppress header showing file name.-v
: Show file name header (default behavior).
Examples and Use Cases
Display the First 10 Lines of a File
head filename.txt
- Outputs the first 10 lines of
filename.txt
.
Display the First 20 Lines of a File
head -n 20 filename.txt
- Outputs the first 20 lines of
filename.txt
.
Display the First 10 Bytes of a File
head -c 10 filename.txt
- Outputs the first 10 bytes of
filename.txt
.
Display the First 10 Lines of Multiple Files
head file1.txt file2.txt
- Outputs the first 10 lines of both
file1.txt
andfile2.txt
.
Display the First 5 Lines of a File
head -n 5 filename.txt
- Outputs the first 5 lines of
filename.txt
.
Suppress Header Showing File Name
head -n 10 -q filename.txt
- Outputs the first 10 lines without showing the file name header.
Display the First 10 Lines of a File with a Specific Byte Range
head -c 50 filename.txt
- Outputs the first 50 bytes of
filename.txt
.
View the First 10 Lines of a Pipe Output
cat filename.txt | head
- Outputs the first 10 lines of the content piped from
filename.txt
.
Combine with -n
and -c
Options
head -n 15 -c 100 filename.txt
- Outputs the first 100 bytes of the first 15 lines of
filename.txt
.
Additional Information
Man Page: For more details, you can refer to the
head
man page:man head
This cheatsheet covers the most common usages and options for the head
command. For more detailed information, you can always refer to the head
man page. Let me know if you need more information or additional examples!
Subscribe to my newsletter
Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by