head(1)
Output the first part of files.
UbuntuDebianFedoraArch
Synopsis
head [OPTION]... [FILE]...Description
Print the first 10 lines of each FILE to standard output. If multiple files are specified, each is preceded by a header showing the filename. If no FILE is given, or FILE is '-', read from standard input.
By default, head outputs 10 lines, but this can be changed with options to output a specific number of lines or bytes instead.
Common options
| Flag | What it does |
|---|---|
-n NUM | print the first NUM lines instead of 10 |
-c NUM | print the first NUM bytes |
-v | always print filename headers, even for single file |
-q | never print filename headers |
-z | use null character as line delimiter instead of newline |
Examples
Display the first 5 lines of the syslog file
head -n 5 /var/log/syslogShow the first 100 bytes of myfile.txt
head -c 100 myfile.txtDisplay first 6 lines of process list (header + 5 processes)
ps aux | head -n 6Print the first line of each .txt file with headers
head -n 1 *.txtShow first 20 lines from each of two log files
head -20 file1.log file2.logPipe output through head to limit to 50 lines
cat largefile.txt | head -n 50Display all lines except the last 5 of the document
head -n -5 document.txt