first edited September 24, 2017 16:25:02
Summary
I. Cure command
Two. grep and regular expressions
Three. Sed and regular expressions
Four. Awk and regular expressions
Five. Other commands
Homework
Summary today
Summary
Citation: Mr. Haifeng
- How to cure commands
- Regular expressions under grep and SED
I. Cure command
- Shell Login
- /etc/profile
- /etc/bashrc
- /root/.bashrc
- /root/.bash_profile
- /etc/profile.d/a.sh
- Non-Shell landing
- /root/.bashrc
- /etc/bashrc
- /etc/profile.d/a.sh
Two. grep and regular expressions
- Grep
- -N: Show line numbers
- -O: Show only matching content
- -Q: Silent mode, no output, you have to use $? To determine the success of the execution, that is, there is no filtering to the desired content
- -L: If the match succeeds, only the file name is printed, the failure is not printed, usually-rl together, grep-rl ' root '/etc
- -A: If the match is successful, the matching row and the subsequent n rows are printed together
- -B: If the match succeeds, the matching row and its first n rows are printed together
- -C: If the match succeeds, the matching row and its n rows are printed together
- -C: If the match succeeds, the number of rows to match is printed
- -e: Equals Egrep, extended
- -I: Ignore case
- -V: Inverse, mismatch
- -W: Match word
- The regular introduction
- ^: Beginning of the line
- $: End of line
- . : Any single character other than line break
- . *: All characters
- *: 0 or more leading characters
- +: One or more leading characters
- ? : A leading character 0 or one
- X{M}: X appears m times
- X{m,}: X appears m times to multiple times (at least m times)
- X{m,n}: Appears m to n times
- []: Any character within a group of characters
- [^]: reverse each character within a character group (does not match each character in a group of characters)
- ^[^]: A line that begins with a character in a non-character group
- \-: Can only be placed at the end
- [A-z]: lowercase letters
- [A-z]: uppercase
- [A-Z]: lowercase and uppercase letters
- Regular expressions and wildcard characters
- Wildcard: Use with commands
- Regular expressions: Generally used for text processing
Three. Sed and regular expressions
- SED syntax
- sed [options] ' command ' in_file[s]
- Options section
- Sed-n ' action ': Silent
- Sed-e ' actions ': multiple rules
- Sed-i ' action ': directly modify read content and write
- Sed-f ' action ': write the action in a file;
- Command section
- ' [Address 1, Address 2] [function] [parameter (tag)] '
- method of addressing 1. Number 2. Regular
- Function
- Delete and change
- A rear plug
- C Replace
- I front insert
- D Delete
- Input/Output
- P Print matching line general and-n parameter to mask default output
- R read in from file
- W Write to File
- s string Substitution s/old/new/[g] (g means all modifications in one line)
- (): Save matched characters for reverse reference \ n use up to 9 label label order from left to right
Four. Awk and regular expressions
- awk syntax: awk [options] ' commands ' files
- -F defines the field delimiter, the default delimiter is a contiguous space or tab, and defines the interval symbol with the-f parameter in option
- Use The order of 2,$3 to represent the different fields of each row in files separated by the interval symbol
- NF variable indicates the number of fields in the current record
- NR indicates the number of rows that awk reads in
- Row handling: Addressing commands
- Addressing methods: Regular, variable, comparison, and relational operations
- ~!~: Match regular or mismatched, regular need/regular/Surround
- -V Define variables and assign values can also be borrowed from the shell variable to introduce
- Username=root
- Awk-v var=$username-f: '$1 = = Var{print $1,nr,nf} '/etc/passwd
Five. Other commands
- Cat File | Sort | Uniq: File sort to go heavy
- cut-d delimiter-fm,n: Processing file with delimiter cut to take section M n part
- Du-sh: Statistics File size
- Find path-type f: Finding ordinary files by type
- Find path-name file name: Finding files by name
- Find path-size +30m: Finding files larger than 30M
- Find path-size +10m-size-30m: Find files larger than 10M less than 30M
- Find/-size +2m-type f-name *.txt
Homework
- Regular expressions and character processing
Target file/etc/passwd, using the grep command or Egrep
- All rows containing root are displayed:
- Output any rows that contain bash, and also output the contents of the next two lines, followed by the row:
- Shows how many lines contain nologin.
- Shows that the rows contain root and the line number is output.
- Displays the file in the
- New user
Abominable
Abominate
Anomie
Atomize
Write regular expressions and match them up
Egrep ' A.omi (nabl|nat|z|) E '/etc/passwd
- Built four users
Alex213sb
wpq2222b
Yh438pig
egon666
Egon
Filter out the user name consists of a letter + number + letter Line
[Email protected] ~]# egrep ' ^[a-z]+[0-9]+[a-z]+ '/etc/passwd
- Displays all filenames containing root in/etc directory
- Filter out all comments and all blank lines in/etc/ssh/sshd_config
Grep-v ' ^# '/etc/ssh/sshd_config |grep-v ' ^ *$ '
Summary today
Python Full Stack road Day8