Home > Text Processing & Search > tail

Guide to the tail Command: Viewing the End of a File and Real-Time Monitoring

`tail` command is used in Linux and Unix-like operating systems to output the last part of a text file (defaulting to 10 lines). It is an essential tool for monitoring log files in real-time or quickly checking recent changes to a file. In this guide, learn the various usages and useful options of the `tail` command.

Overview of tail

`tail` command is specialized in showing the 'tail' part of a file, that is, the most recently added content. This contrasts with the `head` command, which shows the beginning part of a file. Notably, the `--follow` (or `-f`) option outputs new content added to the file in real-time, making it extremely useful for server log monitoring.

Main Role of tail

`tail` command is mainly used for the following purposes:

Key Use Cases

  • Log File Monitoring: Monitor the log files of servers or applications in real-time to detect issues early.
  • Check File Changes: Quickly grasp what content has been added by checking the last part of the file.
  • Data Streaming: Process data by passing the output of `tail` to other commands through pipelines (`|`).

Key tail Command Options

`tail` command offers various options for specifying the number of lines/bytes to output, real-time monitoring, processing multiple files, and more.

1. Specify Output Range

2. Real-Time Monitoring and File Processing

Generated command:

Try combining the commands.

Description:

`tail` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn how to effectively monitor log files and check recent changes to files through various usage examples of the `tail` command.

Check the last 10 lines of a log file

tail /var/log/apache2/access.log

Outputs the most recent 10 lines of the Apache web server's access log file `access.log`.

Monitor a log file in real-time

tail -f /var/log/syslog

Immediately outputs to the terminal whenever new content is added to the system log file `syslog`. Can be stopped with `Ctrl+C`.

Check the last 50 lines of a specific file

tail -n 50 /var/log/application.log

Outputs the most recent 50 lines of the `application.log` file.

Simultaneously monitor multiple log files in real-time

tail -f /var/log/nginx/access.log /var/log/nginx/error.log

Tracks both `access.log` and `error.log` files in real-time. Each file's output is distinguished by its file name.

Real-time monitoring considering log rotation

tail -F /var/log/messages

Tracks the latest logs without interruption even when log files are periodically renamed or newly created (log rotation).

Output from a specific point in a file to the end

tail +100 large_data.txt

Outputs all lines from `start_line_number` to the end of the file. You can specify the starting line number using `+`.


Same category commands