Common Script Commands

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.