Cheat Sheet #day58 - tail
tail
Command Cheatsheet
The tail
command in Unix-like operating systems is used to display the last part of a file. Here’s a quick reference guide:
Basic Syntax
tail [OPTION]... [FILE]...
Common Options
-n NUM
,--lines=NUM
: Output the last NUM lines. Default is 10.tail -n 20 file.txt
-c NUM
,--bytes=NUM
: Output the last NUM bytes.tail -c 100 file.txt
-f
,--follow
: Output appended data as the file grows. Useful for monitoring log files.tail -f /var/log/syslog
-F
,--follow=name --retry
: Similar to-f
, but will try to reopen the file if it is moved or rotated.tail -F /var/log/syslog
-q
,--quiet
,--silent
: Never output headers giving file names.tail -q file1.txt file2.txt
-v
,--verbose
: Always output headers giving file names.tail -v file.txt
Examples
Display the last 10 lines of a file:
tail file.txt
Display the last 20 lines of a file:
tail -n 20 file.txt
Display the last 100 bytes of a file:
tail -c 100 file.txt
Follow a log file in real-time:
tail -f /var/log/syslog
Follow a log file and retry if it is rotated:
tail -F /var/log/syslog
Display the last 10 lines of multiple files:
tail file1.txt file2.txt
Display the last 10 lines of multiple files with headers:
tail -v file1.txt file2.txt
Quiet mode for multiple files without headers:
tail -q file1.txt file2.txt
Additional Information
Display help:
tail --help
View
tail
manual page:man tail
This cheatsheet covers the essential options and usage scenarios for the tail
command. For more advanced features, refer to the man
page or use tail --help
.
Subscribe to my newsletter
Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by