The tail command is used to display the end portion of a file. Here are some common usages:
-
Display the last 10 lines of a file (default behavior):
tail filename.txt -
Display a specific number of lines:
To display the last 5 lines of a file:tail -n 5 filename.txt -
Display lines starting from a specific line number:
To display lines starting from line 10:tail -n +10 filename.txt -
Follow a file in real-time (useful for log files):
To continuously monitor a file for new lines:tail -f filename.txt -
Combine with other commands:
You can pipe the output oftailto other commands. For example, to count the number of lines in the last 10 lines of a file:tail filename.txt | wc -l
These examples should help you get started with using the tail command effectively.
