1. Return to the main knowledge points of this course
chmod, Chown, Umask, grep, Egrep
Rights Management:
Rights Management : chmod
Affiliation Management : Chown, Chgrp
File Matte Code:umask
grep: text Filtering tool;Egrep:grep 's extended version
2.grep Basic Syntax
grep [OPTIONS] PATTERN [FILE ...] :
Options:
--color=auto: The matching to the string to do highlighting;
-V: The display mode does not match the row;
-I: ignore character case;
-O: displays only strings that can be matched to the pattern;
-Q: silent mode;
-E: Using extended regular expressions;
The metacharacters of the basic regular expression:
Character Matching:
.: matches any single character;
[]: matches any single character within the specified range;
[^] : matches any single character within the specified range;
[: Lower:], [: Upper:], ...
Number of occurrences: used to specify the number of times after the character;
*: any time;
Abxy
Xay
Xxxxxxxy
grep "X*y"
\? : 0 or 1 times;
grep "X\?y"
\+:1 or more times ;
\{m\}: Precisely limited to m times;
\{m,n\}: at least m times, up to n times,[M,n]
\{0,n\}: up to n times;
\{m,\}: At least m times;
. *: matches any character of any length;
Location anchoring:
^: anchor at the beginning of the line, for the leftmost mode;
$: end of line anchoring; for the rightmost side of the pattern;
\< \b: The first anchor of the word; the left side of the pattern used to denote the word ;
\> \b: the ending anchor; the right side of the pattern used to represent the word ;
^$: blank line;
Group:\ (\)
The contents of the pattern in the grouped parentheses are recorded by the regular expression engine during execution, and the built-in variables are saved: The variables are \1, \2, ...
\1: from the left, the first opening parenthesis, and the matching right parenthesis in the middle of the pattern match to the content;
\2:
3.display The lines in the /etc/passwd file that end with bash
#grep "bash$"/etc/passwd
4.display the two-digit or three-digit number in the/etc/passwd file
#grep "\<[1-9][0-9]\{1,2\}\>"/etc/passwd
5. Display ' netstat-tan ' command results with ' LISTEN ' followed by 0 ,1 lines ending with one or more whitespace characters
# Netstat-tan |grep-n "\<listen[[:space:]]*$"
6 bash testbash basher nologin user ( nologin user's Span style= "font-family: ' Times New Roman ';" >shell /sbin/ Nologin /etc a row in the /passwd file that has the same user name as its shell name
#useradd bash#useradd testbash#useradd basher#useradd nologin-s/sbin/nologin#grep "^\ (\<[[:alnum:]]\+\>\). *\1 $ "/etc/passwd
8, find A word in the/etc/rc.d/init.d/functions file (the middle of the word can be underlined) followed by a set of parentheses line
grep "\<[[:alnum:]_]\+\> ()"/etc/rc.d/init.d/functions
9, use echo to output a path, and then egrep find its path base name; further use egrep to remove its directory name
#echo/home/mysql/xo/test.sh |grep '. * *
Remove directory name I don't want to write it
Find the number between 1-255 in the ifconfig command Execution result
Ifconfig |grep-e "\< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]) \> "
This is the only temporary level that can be written.
grep Regular Expression