Skip to content
Linuxinfra.com
Menu
  • Home
  • Linux Security
  • Linux Administration
    • Linux History
    • Why Linux is Better?
    • What Are Linux Distributions?
    • Linux kernel and shell
    • Processes in Linux/Unix
    • Linux Basic Commands
  • Cyber Security
    • PCI DSS
      • Module 1: Introduction to PCI DSS
      • Module 2: PCI DSS Requirements Overview
      • Module 3: Scope of PCI DSS Compliance
      • Module 4: Risk Management and Vulnerability Assessments
      • Module 5: Implementing and Maintaining PCI DSS
      • Module 6: Compliance Validation and Reporting
      • Module 7: Best Practices and Case Studies for PCI DSS
      • Module 8: Updates and Future of PCI DSS
Menu
tail command

Mastering the tail Command: Monitoring and Viewing the End of Files in Linux

Posted on August 26, 2024

The tail command in Linux is used to display the last part of a file or the last few lines of a file. It’s especially useful for monitoring log files in real-time, as it can continuously display new lines as they are added to the file. By default, tail shows the last 10 lines of a file, but you can customize this behavior with various options.

Basic usage:

tail [options] [file...]

Common options:

  1. -n [number], –lines=[number] Display the last [number] lines of the file Example: tail -n 20 file.txt
  2. -f, –follow Output appended data as the file grows Example: tail -f log_file.txt
  3. -F Similar to -f, but will keep trying to open a file if it becomes inaccessible
  4. -c [number], –bytes=[number] Output the last [number] bytes of the file Example: tail -c 100 file.txt
  5. –pid=[PID] With -f, terminate after process ID, PID dies
  6. -q, –quiet, –silent Never output headers giving file names
  7. -v, –verbose Always output headers giving file names
  8. –retry Keep trying to open a file even if it is inaccessible when tail starts
  9. -s [seconds], –sleep-interval=[seconds] With -f, sleep for approximately [seconds] seconds between iterations
  10. +[number] Start output from line [number] Example: tail +10 file.txt (starts output from the 10th line)

Examples:

  1. Display the last 10 lines of a file (default behavior):

2 .Display the last 50 lines of a file:

3. Follow the growth of a log file in real-time:

tail -f /var/log/syslog

The tail command is particularly useful for monitoring log files, viewing the most recent entries in a file, or following file changes in real-time.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

cloud infrastructure community support customizability data protection developer tools free software hardware support lightweight Linux Linux applications Linux command line Linux Community Linux community support Linux development Linux Distributions Linux for old hardware Linux for servers Linux graphical interface Linux installation Linux Kernel Linux package manager Linux performance Linux rolling release linux security Linux security tools Linux server Linux software Linux support Linux terminal Linux updates multitasking multiuser networking no bloatware open-source performance privacy privacy control programming scalability secure OS security software repository stability system resources

  • January 2025
  • November 2024
  • September 2024
  • August 2024
  • March 2024
  • January 2024
  • December 2023
©2025 Linuxinfra.com | Design: Newspaperly WordPress Theme