Text
head
Print the beginning of files.
textfilepreviewbeginninglines
Additional Notes
head prints the first part of a file or input stream. By default, it shows the first 10 lines.
It is useful when you want to preview a file without opening the whole thing.
Syntax
head [options] [file...]
Parameters
options: Flags that change howheadbehaves.file: Text file to read or process.
Common Options
-n N,--lines=N: Print the firstNlines.-c N,--bytes=N: Print the firstNbytes.-q,--quiet: Do not print file headers when reading multiple files.-v,--verbose: Always print file headers.
Examples
head file.txt
Show the first 10 lines.
head -n 20 app.log
Show the first 20 lines.
head -c 100 data.bin
Show the first 100 bytes.
head *.log
Preview multiple log files.
command | head
Show only the beginning of command output.
Practical Notes
- Use
tailto view the end of a file. - Use
lessfor scrolling and searching. headis safe for large files because it stops early.- For CSV files,
head -n 1 file.csvoften shows the header.