head command
Display lines from the top of files or command outputs.
Linux · Head, Tail, and Sed Commands
Linux · Lesson
Master the head, tail, and sed commands for text manipulation in Linux. Practical examples for log analysis and file processing.
Linux provides powerful text-processing utilities for reading, filtering and modifying file contents directly from the terminal.
The head command displays lines from the beginning of files, while the tail command displays lines from the end.
The sed command is a stream editor used for advanced text manipulation operations such as printing, replacing, deleting, inserting and appending text.
Display lines from the top of files or command outputs.
Display or monitor lines from the bottom of files.
Perform advanced stream editing and text-processing operations.
The following examples demonstrate how to use head, tail and sed commands for text processing and file management in Linux.
Display lines from the top of a file. By default, head shows the first 10 lines.
Display lines from the bottom of a file or command output.
Monitor files in real-time and display updates continuously.
Use sed to print specific lines, ranges or multiple line numbers.
Replace text patterns using sed substitution operations.
Delete specific lines or line ranges using sed.
Insert text before a specific line using sed.
Append text after a specific line using sed.
/etc/passwd using head.tail -n 6.tail -f.sed -n.sed 's/old/new/'.In upcoming lessons, you will continue learning advanced Linux text processing, regular expressions and shell scripting concepts.