In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what are the linux query log commands, which are introduced in great detail and have certain reference value. Friends who are interested must finish reading them.
[background]
To check for online environmental problems, it is necessary to check the log online. And what command to use, can quickly and accurately find the log information we need to find, is also a skill that we need to master.
[command]
There are several Linux view commands: tail,head,cat,tac,more
(I) tail order
Tail [- f] [- c Number |-n Number |-m Number |-b Number |-k Number] [File]
Parameters:
1)-f loop read
2)-Q does not display processing information
3)-v displays detailed processing information
4)-c Number reads the specified file from the Number byte location
5)-n Number reads the specified file from the Number line location
6)-m Number reads the specified file from the Number multibyte 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 this problem.
7)-b Number reads the specified file from the 512-byte block location represented by Number.
8)-k Number reads the specified file from the 1KB block location represented by Number.
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.
Application:
Command meaning
Tail-f test.log view real-time logs
Tail-100f test.log view the last 100 lines of log records
Tail-n 10 test.log query the log of the last 10 lines at the end of the log
Tail-n + 10 test.log query all logs after 10 lines
Tail-fn 100 test.log loop to view the last 100 rows of records in real time
(II) head order
The function is the opposite of tail. How many lines of log are viewed by tail?
Command meaning
Head-n 10 test.log query the first 10 lines of logs in the log file
Head-n-10 test.log query log file all logs except the last 10 lines
(3) cat order
Function
1) display the entire file at once. Cat filename
2) create a file. Cat > filename
3) merge several files into one file. Cat file1 file2 > file
Parameters:
1)-n numbering the number of lines of all output starting at 1
2)-b is similar to-n, except that blank lines are not numbered
3)-s when there are more than two blank lines in a row, it will be replaced by a blank line
4)-the number of bytes displayed by c
5)-n shows the number of rows
Application
1) cat test.log | tail-n 1000 # output the last 1000 lines of the test.log file
2) cat-n test.log | grep "debug" # get the line number of the key log
3) cat filename | tail-n + 3000 | head-n 1000 # starts at line 3000 and displays 1000 lines. That is, 3000cm 3999 lines are displayed
4) cat filename | head-n 3000 | tail-n + 1000 # shows 1000 to 3000 lines
5) cat-n textfile1 > textfile2 # enter the contents of the textfile1 file with a line number and enter it into the textfile2 file
6) cat-b textfile1 textfile2 > > textfile3 # append the contents of textfile1 and textfile2 to textfile3 after adding line numbers (blank lines are not added)
7) cat error.log | grep-C 5 'nick' shows the line in the file file that matches the foo string and 5 lines up and down
Cat error.log | grep-B 5 'nick' displays foo and the first five lines
Cat error.log | grep-A 5 'nick' displays foo and the last 5 lines
(IV) tac order
Function
Tac is to reverse cat, its function is opposite to cat, cat is from the first line to the last line of continuous display, while tac is from the last line to the first line of reverse display.
(5) more order
Function
Similar to cat, but displayed on a page-by-page basis. The basic instruction is displayed by the blank key (space) to the next page, and by the return key (back) to the previous page, and there is a character search function (similar to vi)
Parameters.
1)-number of rows displayed by num at a time
2)-d prompt the user to display [Press space to continue,'q' to quit.] at the bottom of the screen. If the user presses the wrong key, it will display [Press 'h' for instructions.] Not a beep.
3)-l cancel the function that will be paused when a special character ^ L is encountered
4)-f calculates the number of rows based on the actual number of lines, not the number of lines after the automatic line wrap
5)-p does not display each page in a scrolling manner, but clears the screen before displaying the content
6)-c is similar to-p, except that the content is displayed first and then other old data are cleared.
7)-s when there are more than two blank lines in a row, it will be replaced by a blank line
8)-u does not show lower quotation marks (depending on the terminal specified by the environment variable TERM)
9) + / pattern searches for the pattern before each document is displayed, and then starts to display after the string
10) + num displays from line num
Application
If we find too many logs to print on the screen, use the more and less commands
For example: cat-n test.log | grep "condition" | more is printed in pages. Turn the page by clicking the spacebar.
Command meaning
More-s test.log displays the log page by page. If there are two consecutive lines with white lines above, the log is displayed as a blank line.
More + 20 test.log displays log contents from line 20
(VI) grep order
Features:
The above commands are used to find files conveniently, but when looking for files, we often need to find them through some keywords, and the grep command can help us to find them quickly.
Parameters:
[options] main parameters:
-c: outputs only the count of matching rows.
-I: case-insensitive (for single characters only).
-h: the file name is not displayed when querying multiple files.
-l: when querying multiple files, only the file names that contain matching characters are output.
-n: displays matching lines and line numbers.
-s: does not display error messages that do not exist or have no matching text.
-v: displays all lines that do not contain matching text.
The main parameters of the pattern regular expression:
Ignores the original meaning of special characters in regular expressions
^: matches the start line of the regular expression.
$: matches the end line of the regular expression.
/ test # Save the log contents queried by conditions to a file: cat-n log file | grep 'find content' > save location
(7) sed
Application
Sed-n'5 filename 10p'so you can only look at lines 5 through 10 of the file.
Sed-n'/ 2018-02-06 15 purl 05WR 38max Jr. 2018-02-06 15JR 2038nd p 'umltech-scan
Query log by time period: sed-n'/ start time /, / end time / p 'umltech-scan, time format is "yyyy-mm-dd hh:mm:ss"
(8) vi
Application
Find the keyword method of file content:
Execute the command first >: vi filename
Then enter >: / find string
Press n to find the next one, and N (uppercase) to find the previous one
The above is all the contents of the article "what are the linux query log commands?" Thank you for your 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.