Site icon LinuxCommands.site

tail command tutorial in linux/unix with examples and use cases

linux tail command — output the last part of files.

Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name.

The linux tail command corresponds to the linux head command.

syntax

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

options

linux tail examples

Display the last 10 lines of the file

In the following example, we will use tail to display the last 10 lines of the file.

➜  ~ tail /var/log/dmesg

Display the last 3 lines of file content

➜  ~ tail -3 /var/log/dmesg

Tail skip first N lines

from line 20 to the end of the file:

➜  ~ tail +20 /var/log/dmesg

To monitor the write growth of log files

In the following example, we will use the tail command -f option to monitor file changes in real time; As the file content increases, the output is in real time.

➜  ~ tail -f /var/log/dmesg

use tail with pipes(|)

Display the last 2 lines of the first 10 lines of the file dmesg

➜  ~ head -10 /var/log/dmesg | tail -2 

Exit mobile version