Linux Terminal Command: head
The head command is an essential tool in File Manipulation & Viewing. In this tutorial, we will explore what head does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The head command displays the beginning lines or bytes of a file. It defaults to showing the first 10 lines.
Common Options & Syntax
head [options] [arguments]
Here are the most common flags used with head:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
head system.log
What it does: Prints the first 10 lines of ‘system.log’.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
head -n 50 -c 5000 config.json
What it does: Prints the first 50 lines or up to 5000 bytes (-c) of ‘config.json’.
⚙️ Warning & Common Pitfalls
[!WARNING] If multiple files are passed to
head, it outputs a header for each file, which can disrupt automated parser scripts unless disabled with-q.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out:
- which : Locate a command in the user path environment.