Head Command Introduction
The head
command is a powerful Linux utility designed for previewing the initial contents of text files directly from the command line. As a fundamental tool in file manipulation and system administration, head
allows users to quickly inspect the beginning of files without opening them in a full text editor.
Core Functionality of Head Command
The primary purpose of the head
command is to display the first few lines of a file. By default, it shows the first 10 lines, making it an efficient method for rapid file content preview.
head filename.txt
Command Mechanism
graph LR
A[Input File] --> B[Head Command]
B --> C[First 10 Lines]
C --> D[Console Output]
Key Use Cases
Scenario |
Description |
Example |
File Preview |
Quickly view file contents |
head log.txt |
Large File Inspection |
Examine start of large files |
head -n 20 bigdata.csv |
System Log Analysis |
Check recent log entries |
head /var/log/syslog |
Practical Linux Example
## Display first 5 lines of a text file
head -n 5 example.txt
## View first 20 bytes of a file
head -c 20 example.txt
The head
command provides a fast, efficient method for Linux users to preview file contents, supporting various file types and offering flexible line/byte preview options.