In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the tail command in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Tail command syntax
The code is as follows:
Tail [- f] [- c Number |-n Number |-m Number |-b Number |-k Number] [File]
Parameter explanation:
-f this parameter is used to monitor the growth of File files.
-c Number reads the specified file from the Number byte location
-n Number reads the specified file from the Number line location.
-m Number reads the specified file from the Number multi-byte character location, for example, your file assumes that it includes Chinese characters, and if you specify the-c parameter, it may cause truncation, but using-m will avoid the problem.
-b Number reads the specified file from the 512-byte block location represented by Number.
-k Number reads the specified file from the 1KB block location represented by Number.
File specifies the target file name of the operation
In all the above commands, number is involved. If it is not specified, 10 lines are displayed by default. Number can be preceded by a plus or minus sign, indicating whether the offset is calculated from the top or from the tail.
Tail runnable files are generally below / usr/bin/.
1. Command format
Tail [necessary parameters] [Select parameters] [File]
2. Command function:
Used to display the end of the specified file, and when no file is specified, it is processed as input information. Commonly used to view log files.
3. Command parameters:
-f loop read
-Q does not display processing information
-v displays detailed processing information
Number of bytes displayed by-c
-n shows the number of rows
-- pid=PID is used with-f to indicate that it ends after the process ID,PID dies.
-Q,-- quiet,-- silent never outputs the first part of the given file name
-s,-- sleep-interval=S is used with-f to indicate dormancy for S seconds at intervals of each iteration.
4. Use an example:
Example 1: displays the content at the end of the file
Command:
Tail-n 5 log2014.log
Output:
[root@localhost test] # tail-n 5 log2014.log
2014-09
2014-10
2014-11
2014-12
= = [root@localhost test] #
Description:
Show the last five lines of the file
Example 2: loop through the contents of the file
Command:
Tail-f test.log
Output:
[root@localhost ~] # ping 192.168.120.204 > test.log &
[1] 11891 [root@localhost ~] # tail-f test.log
PING 192.168.120.204 (192.168.120.204) 56 (84) bytes of data.
64 bytes from 192.168.120.204: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 192.168.120.204: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.120.204: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=4 ttl=64 time=0.027 ms
64 bytes from 192.168.120.204: icmp_seq=5 ttl=64 time=0.032 ms
64 bytes from 192.168.120.204: icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from 192.168.120.204: icmp_seq=7 ttl=64 time=0.030 ms
64 bytes from 192.168.120.204: icmp_seq=8 ttl=64 time=0.029 ms
64 bytes from 192.168.120.204: icmp_seq=9 ttl=64 time=0.044 ms
64 bytes from 192.168.120.204: icmp_seq=10 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=11 ttl=64 time=0.027 ms
[root@localhost ~] #
Description:
Ping 192.168.120.204 > test.log & / / ping the remote host in the background. The practice of outputting files to test.log; is also used for more than one file monitoring. Terminate with Ctrl+c.
Example 3: display the file from line 5
Command:
Tail-n + 5 log2014.log
Output:
[root@localhost test] # cat log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
= =
[root@localhost test] # tail-n + 5 log2014.log
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
= =
Thank you for reading! This is the end of the article on "how to use tail commands in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.