The Four musketeers in shell programming

Source: Internet
Author: User

Vim command

Replace:

%s/aaa/bbb/

%s/aaa/bbb/g

Regular Expressions:

^ Opening

$ end

[0-9] Number

[A-z] lowercase

[A-z] capitalization

[^a-z] Non-lowercase

{1,3} 1 to 3 times

. Any single character, except \ r \ n

* 0 times to several times

? 0 times to 1 times

+ 1 times to multiple times

SED command 

Suitable for handling row-related

Replace:

Sed ' s/aaa/bbb/g ' xx.sh

Sed-i ' s/aaa/bbb/g ' xx.sh

Sed ' s//\n/g ' xx.sh

Add a space at the beginning of each line:

Sed ' s/^/&/g ' xx.sh

Add one at the end of each line:

Sed ' s/$/& xiaofan/g ' xx.sh

Locate the row containing Nginx and add the ##### #字符 to his next line:

Sed '/nginx/a ###### ' xx.sh

Locate the row containing Nginx and add ##### #字符 to his previous line:

Sed '/nginx/i ###### ' xx.sh

Match a row and print:

Sed-n '/nginx/p ' xx.sh

Print 1--3 Line:

Sed-n ' 1,3p ' xx.sh

Print the first and last line:

Sed-n ' 1p; $p ' xx.sh

grep command

Filtration (combined with regular use)

-E using Perl regular

-V does not match

-N Print line number

-O outputs only matches to content instead of entire rows

-I ignores case

Match the line of the AA string:

grep "AA" xx.sh

Matches the line of the AA string and the top 2 lines:

Grep-b2 "AA" xx.sh

Matches the line of the AA string and the next 2 lines:

GREP-A2 "AA" xx.sh

Matches the line of the AA string and the top and bottom 2 lines:

Grep-2 "AA" xx.sh

awk command

Awk-f ' {print ($)} ' xx.sh

awk ' $3>90 {print $} ' xx.sh

awk ' {if ($1== "Boo" | | $3==84) print $} ' xx.sh

Netstat-an|awk '/^tcp/{++s[$NF]} END {for (i in S) print S[i],i} '

-F Specify delimiter

Full line

First column

$ second Column

$NF last Column

$NR

How many columns NF has

NR number of rows that have been read

Find command

Find./-maxdepth 1-name "*.sh"

Find./-mandepth 1-type f-name "*.sh"

Modified 7 days ago:

Find./-mtime +7

Modified in the same day:

Find./-mtime-1

Find files larger than 20M in the first layer of the current directory:

Find./-maxdepth 1-size +20m-type F

Locate and perform subsequent actions:

Find./-mtime +7 | Xargs RM-RF

Find./-mtime +7 | Xargs RM-RF \;

Find./-mtime +7-exec RM-RF {} \;

Find./-mtime +7-exec cp {}/tmp/\;

The Four musketeers in shell programming

Related Article

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.