Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»tail Command in Linux with Examples

    tail Command in Linux with Examples

    By RahulFebruary 5, 20233 Mins Read

    The tail command in Linux is a powerful tool used for displaying the end of a file. By default, it displays the last 10 lines of a file, but this can be modified by specifying a different number of lines to display. The tail command is often used to monitor log files, debug applications, or view the contents of a file in real time.

    Advertisement

    Syntax

    The basic syntax for using the tail command is as follows:

    1
    tail [options] [file]

    where options are any optional flags or parameters that modify the behavior of the tail command, and the file is the name of the file to display.

    Some common options used with the tail command include:

    • -n: Specifies the number of lines to display. For example, to display the last 20 lines of a file, you would use the following command: tail -n 20 [file]
    • -c: Specifies the number of characters to display. For example, to display the last 100 characters of a file, you would use the following command: tail -c 100 [file]
    • -f: Follow mode, which continually displays the contents of a file as they are added. This is useful for monitoring log files in real time.
    • -q: Quiet mode, which suppresses the output of the file names. This is useful when you are processing multiple files and only want to see the output, without the file names.

    tail Command Examples

    Here are some step-by-step examples of using the tail command:

    1. To display the last 10 lines of a file named file.txt, simply type:
      tail file.txt 
      
    2. To display the last 20 lines of a file named file.txt, use the following command:
      tail -n 20 file.txt
      
    3. To display the last 100 characters of a file named file.txt, use the following command:
      tail -c 100 file.txt
      
    4. To monitor a log file named log.txt in real time, use the following command:
      tail -f log.txt
      
    5. To display the last 10 lines of multiple files, named file1.txt and file2.txt, use the following command:
      tail file1.txt file2.txt
      
    6. To display the last 20 lines of multiple files, named file1.txt and file2.txt, without the file names, use the following command:
      tail -n 20 -q file1.txt file2.txt
      

    Conclusion

    In conclusion, the tail command is an essential tool for any Linux user. Whether you need to monitor log files, debug applications, or simply view the contents of a file, the tail command provides a convenient and efficient way to do so. By using the options available with the tail command, you can easily customize and automate the process, making it an even more valuable tool in your Linux toolkit.

    command file tail
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Implementing a Linux Server Security Audit: Best Practices and Tools

    cp Command in Linux (Copy Files Like a Pro)

    15 Practical Examples of dd Command in Linux

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Python Lambda Functions – A Beginner’s Guide
    • 10 Practical Use Cases for Lambda Functions in Python
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.