$linuxjunkies
>

tail(1)

Display the last part of files, useful for viewing log files and monitoring output in real time.

UbuntuDebianFedoraArch

Synopsis

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

Description

tail prints the last 10 lines of each FILE to standard output. If multiple files are specified, each is preceded by a header showing the filename. It's commonly used to monitor log files, see the end of large files, or follow output as it's written.

When no FILE is given, tail reads from standard input. The -f flag makes tail follow the file as new lines are appended, making it ideal for watching live logs.

Common options

FlagWhat it does
-n NUMoutput the last NUM lines instead of 10
-ffollow the file as it grows; keep reading until interrupted
-Flike -f but re-open the file if it's rotated or deleted
-c NUMoutput the last NUM bytes instead of lines
-qsuppress headers when reading multiple files
-valways print filename headers even with a single file
--pid=PIDwith -f, exit when process PID dies
-s SECwith -f, sleep SEC seconds between checks

Examples

view the last 10 lines of the system log file

tail /var/log/syslog

show the last 20 lines of the authentication log

tail -n 20 /var/log/auth.log

watch new access log entries appear in real time (Ctrl+C to stop)

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

follow log file safely even if it's rotated or replaced

tail -F /var/log/app.log

see the last 15 kernel messages via pipe

dmesg | tail -n 15

output the last 512 bytes of a binary file

tail -c 512 file.bin

show the last 5 lines from both files without headers

tail -q -n 5 file1.txt file2.txt

follow the log until the myapp process exits

tail -f app.log --pid=$(pgrep myapp)

Related commands