Cheat Sheet #day58 - tail

Cloud TunedCloud Tuned
2 min read

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

  1. Display the last 10 lines of a file:

     tail file.txt
    
  2. Display the last 20 lines of a file:

     tail -n 20 file.txt
    
  3. Display the last 100 bytes of a file:

     tail -c 100 file.txt
    
  4. Follow a log file in real-time:

     tail -f /var/log/syslog
    
  5. Follow a log file and retry if it is rotated:

     tail -F /var/log/syslog
    
  6. Display the last 10 lines of multiple files:

     tail file1.txt file2.txt
    
  7. Display the last 10 lines of multiple files with headers:

     tail -v file1.txt file2.txt
    
  8. 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.

0
Subscribe to my newsletter

Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Cloud Tuned
Cloud Tuned