tail
file managementLinux/Unix
The tail command is one of the most frequently used commands in Linux/Unix-like operating systems. tail Output the last part of files
Quick Reference
Command Name:
tail
Category:
file management
Platform:
Linux/Unix
Basic Usage:
tail [options] [arguments]
Common Use Cases
Syntax
tail [OPTION]... [FILE]...
Options
Option | Description |
---|---|
-c, --bytes=NUM |
Output the last NUM bytes; or use -c +NUM to output starting with byte NUM |
-f, --follow[={name|descriptor}] |
Output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent |
-F |
Same as --follow=name --retry |
-n, --lines=NUM |
Output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM |
--max-unchanged-stats=N |
With --follow=name, reopen a FILE which has not changed size after N iterations (default 5) |
--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 |
-v, --verbose |
Always output headers giving file names |
-z, --zero-terminated |
Line delimiter is NUL, not newline |
--help |
Display help and exit |
--version |
Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the tail
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
Display the last 10 lines of a file (default)
tail file.txt
Display the last 20 lines of a file
tail -n 20 file.txt
Display the last 15 bytes of a file
tail -c 15 file.txt
Monitor file for new lines (follow mode)
tail -f log.txt
Advanced Examples:
Monitor multiple files simultaneously
tail -f log1.txt log2.txt
Display the last 10 lines of multiple files with headers
tail file1.txt file2.txt file3.txt