Common Script Commands
1. log on to other servers using SSH
SSH 172.1.2.10
2. grep command
In Linux, The grep command is a powerful text search tool that uses regular expressions to search for text and print Matching lines. Grep stands for Global Regular Expr.Ession Print, which indicates the global regular expression version. Its permission is applied to all users.
| MPs queue
In general, if you want to search for a specific file, use grep, such
Grep "main" test. c, used to search for whether the test. c contains the string main
If you want to search for a command output that contains a string, use | grep, such
Ps-ef | grep
Cat aa. log | grep 'main'
Common parameters:
-C: calculates the number of times to find the 'string'.-I: The Case sensitivity is ignored. Therefore, the Case sensitivity is treated as the same-n: By the way, the output row number-v: reverse selection, that is, the line without 'search string' is displayed! -- Color = auto: You can add the keyword to the color display.
3. query log Content
Query the rows containing the character "error"
Cat log.txt | grep 'error'
Query the number of characters including "error"
Cat log.txt | grep-c 'error'
Query the first 10 rows that contain the character "error"
Cat log.txt | grep 'error'-C 10 (10 rows after-A and 10 rows before-B)
Query the rows that contain the specified Primary errors and redirect them to a newlog.txt
Cat log.txt | grep 'error'> newlog.txt
Query the lines in the compressed package containing the specified Primary errors and redirect them to a newlog.txt
Zcat log.gz | grep 'error'> newlog.txt
Query the lines in the compressed package that contain the specified Primary errors, and split each line into two rows. Take the second row and redirect it to a newlog.txt file.
Zcat log.gz | grep 'error' | cut-d # f2> newlog.txt