The tail command is used to display the end of a file. It is commonly used when working with logs, configuration files, or output data where the most recent entries are located at the bottom of the file.
This command is especially useful for monitoring system or application activity in real time.
Table of Contents
How the command works
The basic structure is:
tail filename.txt
By default, the command shows the last 10 lines of a file.
Changing the number of lines
You can adjust how many lines are displayed using the -n option:
tail -n 20 filename.txt
This displays the last 20 lines of the file.
Real-time file monitoring
One of the most common uses of tail is following a file as it is being updated:
tail -f filename.txt
This keeps the output active and continuously displays new lines as they are added to the file.
Practical use cases
The tail command is commonly used for:
- monitoring error logs in real time
- checking recent access logs
- debugging applications and services
- reviewing the latest system events
Practical implications
Unlike file editors, tail does not modify the file. It only reads and displays content.
When monitoring logs with -f, the process remains active until manually stopped, typically using CTRL + C.
For large log files, tail is often used instead of opening the full file because it focuses only on the most recent activity.
Summary
The tail command displays the end of a file and is frequently used for real-time monitoring of logs and system activity in SSH environments.