How to use `tail` command?

The tail command is used to display the end portion of a file. Here are some common usages:

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

    tail filename.txt
  2. Display a specific number of lines:
    To display the last 5 lines of a file:

    tail -n 5 filename.txt
  3. Display lines starting from a specific line number:
    To display lines starting from line 10:

    tail -n +10 filename.txt
  4. Follow a file in real-time (useful for log files):
    To continuously monitor a file for new lines:

    tail -f filename.txt
  5. Combine with other commands:
    You can pipe the output of tail to other commands. For example, to count the number of lines in the last 10 lines of a file:

    tail filename.txt | wc -l

These examples should help you get started with using the tail command effectively.

0 Comments

no data
Be the first to share your comment!