How to display the last part of the file in the Linux system?

To display the last part of a file, we use the tail command in the Linux system. The tail command is used to display the end of a text file or piped data in the Linux operating system. By default, it displays the last 10 lines of its input to the standard output. It is the complement of the head command.

Syntax

The general syntax of the tail command is as follows −

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

Options

Brief description of options available in the tail command:

Option Description
-c, --bytes=[-]NUM Display the last NUM bytes of each file. Use +NUM to display starting with byte NUM.
-f, --follow Display appended data as the file grows (useful for log files).
-F Same as --follow=name --retry.
-n, --lines=[-]NUM Display the last NUM lines instead of the default 10.
-q, --quiet, --silent Never display headers giving file names.
-v, --verbose Always display headers giving file names.
--pid=PID With -f option, terminate after process ID dies.
--help Display help message and exit.
--version Display version information and exit.

Examples

Basic Usage

By default, the tail command prints the last ten lines. First, let's create a sample file with multiple lines:

$ cat > text.txt
First line...
Second line...
Third line...
Fourth line...
Fifth line...
Sixth line...
Seventh line...
Eighth line...
Ninth line...
Tenth line...
Eleventh line...
Twelfth line...

Now, use the tail command to display the last 10 lines:

$ tail text.txt
Third line...
Fourth line...
Fifth line...
Sixth line...
Seventh line...
Eighth line...
Ninth line...
Tenth line...
Eleventh line...
Twelfth line...

Display Specific Number of Lines

To display the last n lines, use the -n option. For example, to display the last 4 lines:

$ tail -n 4 text.txt
Ninth line...
Tenth line...
Eleventh line...
Twelfth line...

Display Last Bytes

To display the last 50 bytes of a file:

$ tail -c 50 text.txt

Follow File Changes

The -f option is particularly useful for monitoring log files in real-time:

$ tail -f /var/log/syslog

Common Use Cases

  • Log monitoring − Use tail -f to watch log files for new entries

  • File inspection − Quickly view the end of large files without opening them completely

  • Data processing − Extract recent records from data files

  • System administration − Monitor system logs and application outputs

Conclusion

The tail command is an essential Linux utility for viewing the end portions of files. It's particularly valuable for system administrators monitoring log files and developers tracking application outputs. The -f option makes it indispensable for real-time file monitoring.

Updated on: 2026-03-17T09:01:38+05:30

21K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements