In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces linux how to view the last few lines of the file, the article is very detailed, has a certain reference value, interested friends must read it!
Effect picture
Tail-n 20 filename
Description: displays the last 20 lines of filename.
How to use tail Command under Linux
The purpose of the linux tail command is to output the last part of the specified file to a standard device in accordance with the requirements, usually the terminal. Generally speaking, it is to display the last few lines of a file to the terminal. If the file is updated, tail will take the initiative to refresh itself to ensure that you see the latest contents of the file.
1. Tail command syntax
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. The Number can be preceded by a plus or minus sign, indicating whether the offset is calculated from the top or the tail.
Tail runnable files are generally below / usr/bin/.
2. Demonstration example of how to use tail command
1. Tail-f filename
Note: monitor the tail content of the filename file (default 10 lines, equivalent to adding the parameter-n 10), refresh the display on the screen. Exit and press CTRL+C.
2. Tail-n 20 filename
Description: displays the last 20 lines of filename.
3. Tail-n + 20 filename
Description: displays the first 20 lines of filename.
4. Tail-r-n 10 filename
Description: display the last 10 lines of filename in reverse order.
Add:
Commands that are similar to tail functions include:
Cat displays the contents of the archive from the first line.
Tac displays the contents of the file from the last line.
More pagination displays the contents of the file.
Less is similar to more, but supports paging forward
Head shows only the first few lines
Tail shows only the next few lines
N display the contents of the file with a line number
Od displays the contents of the file in binary mode
1. View the text file header n lines
Head-n 200 filename #-200 can be replaced with any number
2. View the last n lines of the text file
Tail-n 200 filename #-200 can be replaced with any number
3. View the number of lines of the text file
Wc-l filename
Linux-Centos file to see how to display the last few lines, certain lines
1. Show the last 20 lines
Tail-n 20 filename
Such as tail-n 20 log.txt
two。 Show middle 20, starting at 1000
Cat log.txt | tail-n + 1000 | head-n 20
Note: tail-n + line number means to start with more or less lines, if it is tail-n-line = = tail-n line means how many lines at the end of the file
Data of the first 20 rows of head-n 20
3. You can also use the sed command
Such as sed-n '100120p' log.txt 100 to 120 rows of data.
These are all the contents of the article "how to view the next few lines of a file by linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.