The head Command in Linux: A SOC Analyst's Fast-Track Tool for Log Triage and Incident Response
It's 2:47 AM and a SOC analyst on the graveyard shift just got paged for a spike in failed SSH logins on a production jump box. The auth log is over 400,000 lines long by the time she opens it. She doesn't have time to scroll. She doesn't need the whole file. She needs the first burst of events — the moment the attack started — before the noise buries the signal. One command gets her there in under two seconds: head.
Most people learn head as a beginner's Linux command and move on. But in a real SOC environment, head is a first-response triage tool. It's how analysts sample massive log files, verify data before running expensive parsing jobs, and confirm the shape of an incident before committing to a full investigation. This guide walks through head the way it's actually used on the floor — not just the syntax, but the reasoning behind it.
Table of Contents
- What head Actually Does
- Why SOC Analysts Rely on head
- Core head Commands With Real Explanations
- Real-World Scenario: Triaging a Brute-Force Alert
- Using head in Detection and Threat Hunting Workflows
- Common Mistakes and Pitfalls
- Expert Tips From the Field
- Related Reading
- FAQ
- Conclusion
What head Actually Does
head is a core Linux/Unix utility that prints the beginning of a file or input stream. By default, it shows the first 10 lines — but every flag changes what "beginning" means, and that flexibility is exactly why it's still relevant on modern SOC workstations, cloud bastion hosts, and forensic images decades after it was written.
Unlike cat, which dumps an entire file, head is deliberately limited. That limitation is the feature. When you're staring down a multi-gigabyte log file over a slow SSH session, you don't want the whole thing — you want a fast, safe preview.
Why SOC Analysts Rely on head
Security logs — auth logs, web server access logs, firewall logs, EDR exports — grow fast and grow ugly. A single compromised host can generate hundreds of thousands of lines in a few hours during an active attack. Before an analyst runs grep, builds a Splunk query, or ships logs to a SIEM, they usually eyeball the file structure first. That's where head comes in:
- Confirming log format before writing a parsing script (CSV headers, JSON structure, syslog format)
- Sampling the start of a suspicious file without triggering a full read (important on resource-constrained incident response boxes)
- Checking timestamps at the top of a log to establish a rough starting point for a timeline
- Verifying that a log export or SIEM dump actually contains data before trusting downstream automation
Core head Commands With Real Explanations
Show the first 10 lines (default behavior)
head file.txt
What it does: Prints the first 10 lines of the file. When to use it: Your default move when opening any unfamiliar log for the first time — a quick sanity check before deeper analysis. Expected output: The literal first 10 lines, unmodified, in original order.
Show the first N lines
head -n 5 file.txt
What it does: Displays exactly 5 lines instead of the default 10. When to use it: Useful when you only need a header row or a small sample, like checking a CSV export's column structure. Expected output: The first 5 lines exactly.
View multiple files at once
head file1.txt file2.txt
What it does: Shows the first 10 lines of each file, clearly labeled with filenames. When to use it: Comparing multiple log exports from different hosts during a multi-system incident, like checking whether all affected endpoints show the same initial attack signature. Expected output: Filename headers followed by each file's first 10 lines.
Display the first N bytes
head -c 20 file.txt
What it does: Prints the first 20 bytes rather than lines. When to use it: Critical for binary analysis — checking a file's magic bytes/header to identify true file type, which matters when malware is disguised with a fake extension. Expected output: Raw byte content, often unreadable for non-text files, which itself is diagnostic information.
Combine with cat via a pipe
cat file.txt | head -n 15
What it does: Pipes the full file content through head, printing only the first 15 lines. When to use it: Mostly seen in scripts chaining multiple commands together, though direct head -n 15 file.txt is more efficient on its own. Expected output: The first 15 lines of the file.
Show all except the last N lines
head -n -5 file.txt
What it does: Prints everything except the last 5 lines. When to use it: Trimming incomplete trailing entries from a log that's still being written to, so you don't analyze a partial, mid-write line. Expected output: The full file minus the final 5 lines.
Show all except the last N bytes
head -c -20 file.txt
What it does: Displays the file content minus the last 20 bytes. When to use it: Rare, but useful in forensic byte-level trimming of truncated or corrupted binary evidence. Expected output: All bytes except the final 20.
Read from standard input
echo -e "one\ntwo\nthree" | head -n 2
What it does: Takes piped input instead of a file and returns the first 2 lines. When to use it: Common when chaining live command output (like process lists or network connections) rather than static files. Expected output: "one" and "two".
View the beginning of a log file
head -n 50 /var/log/syslog
What it does: Shows the first 50 lines of the system log. When to use it: Checking when logging started for the current log file, useful when correlating log rotation timing with an incident window. Expected output: 50 lines of syslog entries with timestamps.
Preview a CSV file
head -n 10 data.csv
What it does: Shows the first 10 lines including the header row. When to use it: Before importing threat intel feeds or IOC lists into a SIEM, to confirm column order and delimiter. Expected output: Header row plus 9 data rows.
Combine with grep
grep "ERROR" logfile.log | head -n 10
What it does: Filters for lines containing "ERROR", then limits output to the first 10 matches. When to use it: One of the most common SOC one-liners — quickly sampling error or alert patterns without flooding the terminal. Expected output: Up to 10 matching lines.
Save the first lines to a file
head -n 10 file.txt > preview.txt
What it does: Redirects the first 10 lines into a new file called preview.txt. When to use it: Creating a lightweight sample file to share with a teammate or attach to a ticket, without sending an entire multi-GB log. Expected output: A new file, preview.txt, containing 10 lines.
View the beginning of multiple logs
head -n 5 *.log
What it does: Shows the first 5 lines of every .log file in the current directory. When to use it: Fast structural check across an entire log directory during initial incident scoping. Expected output: Filename headers followed by 5 lines per log file.
Show the first bytes of a binary file
head -c 16 file.bin
What it does: Displays the first 16 bytes of a binary file. When to use it: Quick manual file-type verification — many file formats have unique magic bytes in their first few bytes (PE, ELF, ZIP, PDF signatures). Expected output: Often garbled text/hex-like output representing raw binary data.
Real-World Scenario: Triaging a Brute-Force Alert
Consider a mid-sized SaaS company running Ubuntu servers behind a bastion host. The SIEM fires an alert: unusual volume of failed SSH authentication attempts against a single production server. The on-call analyst SSHes into the box and finds /var/log/auth.log sitting at 1.2 million lines.
Instead of opening the whole file in a text editor (which could hang the session or eat memory on a resource-limited box), the analyst runs:
head -n 20 /var/log/auth.log
This confirms the log's current rotation start time and format. Next, to see when the failed attempts actually began, they combine it with grep:
grep "Failed password" /var/log/auth.log | head -n 10
Within seconds, the first 10 failed login attempts appear — complete with source IPs and usernames. That's the starting timestamp the analyst needs to build an incident timeline, correlate with firewall logs, and determine whether the attack is still in progress or already over.
Using head in Detection and Threat Hunting Workflows
head rarely works alone — it's a supporting tool in a larger detection chain. Some patterns seen regularly in SOC playbooks and threat hunting runbooks:
- Log format validation: Before ingesting a new log source into a SIEM, analysts run
headto confirm the field structure matches the expected parser configuration. - IOC feed sanity checks: Threat intel feeds delivered as CSV or JSON get a quick
headpass to confirm they downloaded correctly and aren't truncated or corrupted. - File type verification during malware triage: Combined with
-c, analysts check magic bytes to confirm a suspicious file isn't disguised with a mismatched extension — a classic evasion technique. - Rapid multi-host comparison: During a suspected lateral movement incident, running
head -n 5 *.logacross collected logs from multiple hosts quickly reveals whether they share a common attack signature at the top of each file.
Common Mistakes and Pitfalls
- Assuming the first lines represent the whole incident: head only shows the start of a file — pair it with
tailor full-text search to avoid missing the most recent, and often most relevant, activity. - Forgetting log rotation: The "beginning" of a rotated log file might not align with when the incident actually started — always confirm rotation timestamps first.
- Using head on live-writing files without accounting for buffering: On files actively being written to, the last few lines can be incomplete;
head -n -Ncan help avoid analyzing partial entries. - Treating byte output as safe to paste anywhere: Binary byte output from
head -ccan contain non-printable characters that break terminal formatting or corrupt logs if redirected carelessly.
Expert Tips From the Field
- Pair
headwithwc -lfirst to know the total line count before deciding how much of the file actually needs sampling. - For JSON logs, combine
headwithjqto preview only the first few well-formatted records instead of raw truncated JSON. - When documenting an incident, always note the exact
headcommand used in your case notes — reproducibility matters during post-incident review. - On forensic images, always work from a copy — never run commands, even read-only ones like
head, directly against original evidence.
Related Cybersecurity Topics You Should Explore
- Elementor Pro Bug Lets Hackers Upload PHP — No Login Needed
- tac Command Tutorial: Reverse Logs Fast for Faster Threat Detection
- ToxicPanda 2.0: The Android Trojan Now Hacking 349 Banks
- Windows 11 24H2 Support Ends Oct 13 — Are You at Risk?
- Cat Command in Linux: The SOC Analyst's Secret Weapon
- How a Fake VNC Login Turned Into Full Root Access on macOS
- reconFTW Tutorial: The Recon Tool That Found My Hidden Bounty
- TP-Link Router Flaw Lets Hackers Skip Login Entirely — Here's What's at Risk
- This subfinder Fork Cuts Recon Time in Half — subfaster Review
- 737 Fake VPN Extensions Are Spying on Chrome Users Right Now
- GhostDesk Spyware Alert: Fake CCleaner Steals Passwords & Crypto
- Zoomsday Flaw: Hackers Hijack Zoom Users With Zero Clicks
- SonicWall SMA1000 Flaws Now Fuel Ransomware Attacks – CISA Warns
- HP ThinPro's 'Encrypted' Drives Aren't Actually Safe — Here's Why
- GRR Rapid Response: The Free Google Tool That Hacks 100K PCs Remotely
FAQ
Q1: What's the difference between head and cat?
cat prints an entire file's contents, while head limits output to a specified number of lines or bytes from the beginning — making it safer for large files.
Q2: Can head be used on live log files that are actively being written to?
Yes, though for actively growing files, tail -f is typically preferred for watching new entries in real time; head is best for a one-time snapshot of the start.
Q3: Is head available on Windows?
Native Windows lacks head, but it's available through WSL, Git Bash, or Cygwin, and PowerShell offers a similar function via Get-Content -TotalCount.
Q4: Why would a SOC analyst use head -c instead of head -n?
Byte-level output is essential for binary file inspection, such as checking magic bytes to verify true file type during malware analysis.
Q5: Does head modify the original file?
No, head is a read-only command — it never alters or deletes the source file, making it safe to run on evidence and live systems alike.
Q6: How does head handle negative numbers like -n -5?
A negative value tells head to print everything except the last N lines, effectively excluding the tail end rather than limiting the head.
Conclusion
The head command looks trivial on paper — ten lines, a file, done. But in a real SOC workflow, it's one of the fastest ways to sanity-check data before committing time and compute to deeper analysis. Whether it's confirming a log's format before parsing, spotting the first signs of a brute-force attempt, or verifying a suspicious file's true type through its magic bytes, head earns its place in every analyst's daily toolkit. Master the fundamentals, and it becomes second nature during the moments that matter most — the first few minutes of an incident, when speed and clarity decide everything that follows.







