head
Explanation
The head command prints the first part (usually the first 10 lines) of files to standard output. It's incredibly useful for quickly checking the structure of a file, verifying column headers, or looking at the initial contents without opening the entire file.
Basic Syntax
head [OPTION]... [FILE]...
Common Flags and Options
| Flag | Description |
|---|---|
-n, --lines=[-]NUM | Print the first NUM lines instead of the first 10. (If NUM is prefixed with '-', print all but the last NUM lines.) |
-c, --bytes=[-]NUM | Print the first NUM bytes. |
-q, --quiet, --silent | Never print headers giving file names. |
Real-world Examples
-
View the first 10 lines of a file (default):
head file.txt -
View the first 20 lines:
head -n 20 file.txt -
View the first 50 bytes:
head -c 50 file.txt