linux tail command tutorial: tail syntax and tail examples

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.


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


  • -c, –bytes=[+]NUM
    output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file
  • -f
    -f option causes tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the input.
  • -n, –lines=[+]NUM
    output the last NUM lines.
  • –pid=PID
    with -f, terminate after process ID, PID dies
  • -q, –quiet, –silent
    never output headers giving file names
  • –retry
    keep trying to open a file if it is inaccessible
  • -s, –sleep-interval=N
    with -f, sleep for approximately N seconds (default 1.0) between iterations; with inotify and –pid=P, check process P at least once every N seconds
  • -v, –verbose
    always output headers giving file names
  • -z, –zero-terminated
    line delimiter is NUL, not newline

linux tail examples

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

tail-f is usually used for system management to monitor logs

➜  ~ 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 

Recommended Posts:

Linux common commands tutorial and use examples
GNU sed syntax and sed examples
Awk tutorial: awk syntax and awk examples
linux chmod command and linux chown command usage
linux iostat syntax and iostat examples
linux grep command and grep examples
linux top syntax and top examples

Add a Comment

Your email address will not be published. Required fields are marked *