Online Linux Terminal Logo
OnlineLinuxTerminal
Text ProcessingCLI Reference

$head

Output the first part (top lines) of text files.

Syntax DefinitionPOSIX standard
head [OPTIONS] [FILE...]
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `head` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

Overview & How head Works

`head` outputs the beginning portion of files, displaying the first 10 lines by default. It is ideal for quickly inspecting file headers, CSV schemas, or top log entries without loading massive files into memory.

Common Flags & Command Options

Flag / OptionDescription
-n [NUM]Print the first NUM lines instead of the default 10.
-c [NUM]Print the first NUM bytes of each file.
-qQuiet mode; never print headers giving file names.

Practical Real-World Examples

Example #1View top 5 lines of syslog
head -n 5 /var/log/syslog

Extracts and prints only the first 5 lines of the system log file.

Sample Output:
Aug 28 10:00:01 systemd[1]: Starting Daily apt upgrade... Aug 28 10:00:02 kernel: Booting Linux on physical CPU...

Frequently Asked Questions

How do you view everything except the last 10 lines?

Use `head -n -10 [file]` to output all lines from the start up to the last 10 lines.