tail(1)
Display the last part of files, useful for viewing log files and monitoring output in real time.
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
| Flag | What it does |
|---|---|
-n NUM | output the last NUM lines instead of 10 |
-f | follow the file as it grows; keep reading until interrupted |
-F | like -f but re-open the file if it's rotated or deleted |
-c NUM | output the last NUM bytes instead of lines |
-q | suppress headers when reading multiple files |
-v | always print filename headers even with a single file |
--pid=PID | with -f, exit when process PID dies |
-s SEC | with -f, sleep SEC seconds between checks |
Examples
view the last 10 lines of the system log file
tail /var/log/syslogshow the last 20 lines of the authentication log
tail -n 20 /var/log/auth.logwatch new access log entries appear in real time (Ctrl+C to stop)
tail -f /var/log/nginx/access.logfollow log file safely even if it's rotated or replaced
tail -F /var/log/app.logsee the last 15 kernel messages via pipe
dmesg | tail -n 15output the last 512 bytes of a binary file
tail -c 512 file.binshow the last 5 lines from both files without headers
tail -q -n 5 file1.txt file2.txtfollow the log until the myapp process exits
tail -f app.log --pid=$(pgrep myapp)