Friday, August 11, 2023

Tail Command Example in Linux | How to Use Tail Command in Linux


The tail command in Linux is used to display the last few lines of a text file. By default, it displays the last 10 lines of a file, but you can specify the number of lines you want to display using the `-n` option. Here are some examples:

1. Display the last 10 lines of a file (default behavior):
   
 tail filename.txt
   
2. Display a specific number of lines from the end of a file (e.g., last 20 lines):
   
tail -n 20 filename.txt
   
3. Display the last few lines of multiple files:
   
tail file1.txt file2.txt
   
4. Display the last 5 lines of all .log files in a directory:
   
tail -n 5 *.log
   
5. Display the last 15 lines of a remote file using SSH:
  
 ssh user@hostname "tail -n 15 /path/to/remote/file.txt"
   
6. Display the last lines of a file and continuously update as new lines are added (useful for log files):
   
tail -f filename.log
   
Remember that the tail command is used to display the ending lines of a file. If you want to view the beginning lines, you can use the `head` command.

No comments:

Post a Comment

Installing Jenkins on RHEL 8 is a straightforward process. Here's a step-by-step guide

Introduction  Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) pipelines...