Table of Contents
This tip is about the how to Use tail Command on Linux. So read this free guide, How to Use tail Command on Linux. If you have query related to same article you may contact us.
How to Use tail Command on Linux – Guide
As the name suggests, the tail command is used to display the last values of the file’s contents. The last 10 lines are selected by default. Although we can customize the number of lines by specifying the number in the command. This tutorial show you how to use the tail command. Using tail is an easy way to see the final of files, such as when analyzing logs and other text files that change over time. It can also be combined with other tools for selective real-time monitoring.
In many ways, Linux is similar to other operating systems you may have used, such as: B. Windows, macOS (formerly OS X), or iOS. Like other operating systems, Linux has a graphical user interface and the same types of software you are used to like word processors, image editors, video editors, etc. In many cases, the software creator may have created a Linux version of the same program you used on other systems. In short, if you can use a computer or other electronic device, you can use Linux.
tail command syntax
Before entering how to use the tail command, let’s start by reviewing the basic syntax.
How to Use tail command
In its simplest form, when used without any options, the tail command will display the last 10 lines.
How to Display a specific number of lines
Use the -n (–lines) option to specify the number of lines to show:
You can also omit the letter n and just use the hyphen (-) and the number (no space between them). To display the last 50 lines of a file called filename.txt you would use:
The following example will display the same output as the above commands:
How to Display a specific number of bytes
To show a specific number of bytes, use the -c (–bytes) option.
For example, to display the last 500 bytes of data from the file named filename.txt, you would use:
You can also use a multiplier suffix after the number to specify the number of bytes to show. b multiplies by 512, kB multiplies by 1000, K multiplies by 1024, MB multiplies by 1000000, M multiplies by 1048576, and so on.
The following command will display the last two kilobytes (2048) of the filename.txt file:
To stop the tail command while it looks at a file, press Ctrl+C. To continue monitoring the file when it is recreated, use the -F option.
This option is useful in situations where the tail command is following a log file that rotates. When used with the -F option, the tail command will reopen the file as soon as it is available again.
How to View multiple files
If multiple files are given as input to the tail command, it will display the last ten lines of each file.
This example shows the last 20 lines of the files filename1.txt and filename2.txt:
How to Use Tail with other commands
The tail command can be used in combination with other commands by redirecting standard output to/from other utilities using pipes. For example, to monitor the apache access log file and display only the lines that contain the IP address 192.168.42.12, you would use:
The following ps command will display the top ten running processes ranked by CPU usage:
Final note
I hope you like the guide How to Use tail Command on Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.