tail – Display the last few lines of the specified file on the screen

The tail command is a Linux command that displays the last few lines of a specified file on the screen. It is useful when you need to check the end of a large log file or any other file that is continuously being updated.


The syntax for the tail command is as follows:

tail [OPTION]... [FILE]...

Where [OPTION] is an optional argument that modifies the behavior of the command, and [FILE] is the file that you want to display the last few lines of.

By default, tail displays the last 10 lines of the file. You can specify a different number of lines to display by using the -n option followed by the number of lines you want to display. For example, to display the last 20 lines of a file, you would use the following command:

tail -n 20 filename

tail can also be used to display the contents of multiple files at once. To do this, simply specify the names of the files as additional arguments. For example:

tail file1 file2

This will display the last 10 lines of both file1 and file2.


The tail command has several options that can be used to modify its behavior. The following table lists all available options:

Option Description
-n NUM Specifies the number of lines to display.
-f Displays the last 10 lines of the file and then monitors the file for changes. Any new lines added to the file will be displayed in real-time.
-q Suppresses the display of file names when displaying the last few lines of multiple files.
-v Displays file names when displaying the last few lines of multiple files.
-c NUM Specifies the number of bytes to display instead of lines.
--pid=PID Kills the tail command when the specified process ID (PID) dies.
--retry Monitors the file for changes indefinitely, even if the file is deleted and recreated.

Troubleshooting tips

One common issue with the tail command is that it may not display the latest changes to a file if the file is being written to very quickly. This can be resolved by using the -f option, which will monitor the file for changes and display them in real-time.

Another issue that may come up is that tail may display an error message if it is unable to read the specified file. This can happen if the file does not exist or if the user running the command does not have permission to read the file. In this case, you should check that the file exists and that the user has the necessary permissions to read the file.


  • The tail command is often used in conjunction with other commands, such as grep, to search for specific patterns in a file.
  • The -f option can be useful for monitoring log files in real-time to quickly identify and troubleshoot issues. However, it can also consume a lot of system resources if used on a file that is being written to very quickly.