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.txtDisplay the last 20 lines of a file:
tail -n 20 file.txtDisplay the last 100 bytes of a file:
tail -c 100 file.txtFollow a log file in real-time:
tail -f /var/log/syslogFollow a log file and retry if it is rotated:
tail -F /var/log/syslogDisplay the last 10 lines of multiple files:
tail file1.txt file2.txtDisplay the last 10 lines of multiple files with headers:
tail -v file1.txt file2.txtQuiet mode for multiple files without headers:
tail -q file1.txt file2.txt
Additional Information
Display help:
tail --helpView
tailmanual 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.




