First, access to the user and Rights management
Command:chmod/chown/chgrp/umask
1, chmod (modify file permissions)
Synopsis chmod [OPTION] ... Mode[,mode] ... FILE ... chmod [OPTION] ... Octal-mode file ... chmod [OPTION] ...--reference=rfile file ...
Divided into three categories:
U:owner (owner)
G:group (genus Group)
O:other (Others)
A:all
Three ways to use:
A, =mode uses an equal sign to assign a value, which eliminates the previous attribute. If the permission of a file test is-rwxr-xr--, using chmod u=rw test, the permission of test will be changed to-rw-r-xr-x;
Note: If the = number does not have any more permissions then the permission for that class is---
If you change the properties of a directory to only change the properties of the directory without using parameters, it will not affect the file properties under the directory, such as changing the directory and the properties of the files in the directory using the-R (meaning recursive) parameter.
b, [+|-]mode
such as chmod U+RW test indicates that the owner is given read and write permissions
C 、--reference=rfile file (representing the same permissions to file as the permissions of rfile files)
Example: chmod--reference=test1 test
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/95/wKiom1XnFlbQYsaCAALtvmbqOgw990.jpg "title=" Chmod.jpg "alt=" Wkiom1xnflbqysacaaltvmbqogw990.jpg "/>
2, Chown (modified file owner)
Synopsis Chown [OPTION] ... [OWNER] [: [GROUP]] File ... chown [OPTION] ...--reference=rfile file ...
Two methods of modification
A, chown owner:group file//chown command followed by the owner and the group can be
For example: Chown basher:usera Test//Change the owner of the test file to Basher, the group is changed to UserA
Note: If you only want to make the genus Group just the chown followed: The group property is fine.
such as: Chown:oracle test1
B, chown--reference=rfile file
such as: Chown--reference=test test1//Set the owner and the group of the Test1 to test the owner and the genus Group
Note If you want to modify the directory and the owner of the file in the directory, the genus Group remains chown followed by-R parameter
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/96/wKiom1XnGWGAIoxnAAJwnRTDudI315.jpg "title=" Chown.jpg "alt=" Wkiom1xngwgaioxnaajwnrtdudi315.jpg "/>
3, Chgrp (modify the genus Group of files)
Synopsis chgrp [OPTION] ... GROUP file ... chgrp [OPTION] ...--reference=rfile file ...
Using the same method as the above two, this is not shown here.
4. Umask (Mask Code)//You can modify the permissions of the generated files and directories by setting the mask code
umask=0022 for super users
Umask=0002 for ordinary users
Permissions for the directory =777-umask
Permissions for Files =666-umask
Note: If there is a type of user whose permissions are reduced to the result that the O bit has execute permissions, then the system automatically gives its permission to add 1:
The Umask value set by Umask Vlaue is only valid for the current shell process. If you think of a permanent entry, you should modify the Umask value in the/ETC/BASHRC file.
Example: Setting the Superuser's umask to 0023 after using the root user to create the default permissions for directories and files
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/92/wKioL1XnH-CwOlTZAAOSnL6zfGU319.jpg "title=" Umask.jpg "alt=" Wkiol1xnh-cwoltzaaosnl6zfgu319.jpg "/>
Second, grep and regular expressions
1. Grep:global search REgular expression and print out the line.//global (matches regular expression) and print
Function: Text Search tool, according to user-specified "mode (pattern//here can be regular expression)" to search the target text line by row, and print the matching line;
Pattern: is the filter condition written by the metacharacters of the regular expression and the text character;
Metacharacters: It does not mean its literal meaning, but is used to denote the function of a wildcard or control;
Regular expressions are divided into two categories:
Basic Regular Expressions: BRE
Extended Regular expression: ERE
2. grep use method and Parameters
Synopsis grep [OPTIONS] PATTERN [FILE ...] grep [OPTIONS] [-E PATTERN |-f file] [FILE ...]
options [Options]:
--color=auto: Highlighting the matched text;
-V: The display mode does not match to the row;
-O: Displays only the rows to which the pattern matches;
-I: indicates ignoring case;
-Q: Silent mode, matching but not displaying results
-E: Using extended regular expressions;
Cases:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/96/wKiom1XnI4KBk5aIAAG8rcACMTw559.jpg "title=" Grep.png "alt=" Wkiom1xni4kbk5aiaag8rcacmtw559.jpg "/>
3. Regular expressions
A, the metacharacters of the basic regular expression:
A), character matching:
.: The dot number means matching any single character;
[]: matches any single character within the specified range;
[^]: matches any single character outside the specified range;
[: Alnum:]: Matches the letter and number;
[: Space:]: Match space;
[: Alpha:]: matches the letter;
[: Cntrl:]: Match the control key on the keyboard;
[:d Igit:]: Match number;
[: Lower:]: matches lowercase letters;
[: Upper:]: matches uppercase letters;
[: Xdigit:]: match 16 binary digits;
Example: 650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/93/wKioL1XnLEeyY_YIAAOur5OjIGk360.jpg "title=" grep _char.jpg "alt=" Wkiol1xnleeyy_yiaaour5ojigk360.jpg "/>
b), number of matches:
*: any time;
\?:0 or 1 times;
\+:1 times or more;
\{m\}: precise M-times;
\{m,n\}: At least m times, up to N times, with two special usages;
\{0,n\}: Up to n times;
\{m,\}: at least m times;
. *: Matches any character of any length;
Example: 650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/93/wKioL1XnLuzjd4kkAAK4YI56cvs137.jpg "title=" grep _wc.jpg "alt=" Wkiol1xnluzjd4kkaak4yi56cvs137.jpg "/>
c), Position anchoring:
^: Anchor at the beginning of the line for the leftmost mode;
$: Line end anchor for the right-most side of the pattern;
\<,\b: The first anchor of the word, used to denote the left side of the word pattern;
\>,\b: The ending anchor, used to represent the right side of the word pattern;
^$: Match blank line;
Example: 650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/96/wKiom1XnLbvi5L16AAJMUqrXDys157.jpg "title=" grep _local.jpg "alt=" Wkiom1xnlbvi5l16aajmuqrxdys157.jpg "/>
d), group: \ (\)
The contents of the pattern in the grouped parentheses are recorded by the regular expression engine during execution and stored in the built-in variables, which are \1,\2,...
\1: From the left, the first pair of parentheses in the middle of the pattern match to the content;
Later and so on;
Back reference: Use the variable to refer to the contents of the pattern matching in the preceding grouping brackets;
Example: 650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/93/wKioL1XnMR-g1Rl7AAFpsIkQQ74281.jpg "title=" grep _back.jpg "alt=" Wkiol1xnmr-g1rl7aafpsikqq74281.jpg "/>
3. Egrep Extended Regular expression:
The grep family has three commands:
grep: basic Regular expression
-e: extending regular expressions
-F: Regular expressions are not supported
Egrep: Extending Regular expressions
Fgrep: Regular expressions are not supported
A, extending the metacharacters of regular expressions:
A), character matching:
.: The dot number means matching any single character;
[]: matches any single character within the specified range;
[^]: matches any single character outside the specified range;
b), number of matches:
*: any time;
?: 0 or 1 times;
+: more than 1 times;
{m}: precise m times;
{M,n}: At least m times, up to N times, with two special usages;
{0,n}: up to n times;
{m,}: at least m times;
. *: Matches any character of any length;
c), Position anchoring:
^: Anchor at the beginning of the line for the leftmost mode;
$: Line end anchor for the right-most side of the pattern;
\<,\b: The first anchor of the word, used to denote the left side of the word pattern;
\>,\b: The ending anchor, used to represent the right side of the word pattern;
^$: Match blank line;
d), group: \ (\)
The contents of the pattern in the grouped parentheses are recorded by the regular expression engine during execution and stored in the built-in variables, which are \1,\2,...
\1: From the left, the first pair of parentheses in the middle of the pattern match to the content;
Later and so on;
Back reference: Use the variable to refer to the contents of the pattern matching in the preceding grouping brackets;
e), or
A|b
C|cat: does not represent cat or cat, but is C or cat;
To be written (C|c) at
Because the use of egrep is similar to grep, it is not a cover-up.
Third, the operation
1. Display the lines in the/etc/passwd file that end with bash
grep ' bash$ '/etc/passwd
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/93/wKioL1XnOXmSMV53AAG3Kt0NZHI474.jpg "title=" 1.jpg " alt= "Wkiol1xnoxmsmv53aag3kt0nzhi474.jpg"/>
2. Display the two-digit or three-digit number in the/etc/passwd file
Egrep--color=auto ' ([1-9][1-9]|[ 1-9][1-9][1-9]) '/etc/passwd
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/96/wKiom1XnN2eB4SnzAAbihPItm10435.jpg "title=" 2.jpg " alt= "Wkiom1xnn2eb4snzaabihpitm10435.jpg"/>
3. Display lines with ' LISTEN ' followed by 0, one or more whitespace characters in the ' Netstat-tan ' command result
Netstat-tan | grep--color=auto ' listen[[:space:]]\{0,\}$ '
Netstat-tan | grep--color=auto ' listen[[:space:]]*$ '
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/93/wKioL1XnOaGDzey8AAHvHhylvOo007.jpg "title=" 3.jpg " alt= "Wkiol1xnoagdzey8aahvhhylvoo007.jpg"/>
4. Add user bash, Testbash, basher, and Nologin user (Nologin user's shell is/sbin/nologin), then find the same line in the/etc/passwd file as the user name and its shell name
Useradd Bash
Useradd Testbash
Useradd-s/sbin/nologin Nologin
Egrep ' (^\<[[:alnum:]].*\>). *\1$ '/etc/passwd
Egrep ' (^\<[[:alnum]]{0,}\>) {0,}1$ '/etc/passwd
grep--color=auto ' \ (^\<[[:alnum:]].*\>\). *\1$ '/etc/passwd
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/96/wKiom1XnN5OC6z2bAAFTCBS_QOE088.jpg "title=" 4.jpg " alt= "Wkiom1xnn5oc6z2baaftcbs_qoe088.jpg"/>
5. Display the default shell and UID of root, CentOS, or User1 user on the current system (please create these users beforehand, if not present)
Useradd user1
Useradd CentOS
Egrep ' ^root|^centos|^user '/etc/passwd | Cut-d:-F 1,3,7
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/93/wKioL1XnOceg9SwtAAETfmNB8vY513.jpg "title=" 5.jpg " alt= "Wkiol1xnoceg9swtaaetfmnb8vy513.jpg"/>
6, 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
Egrep ' \<[[:alpha:]].*\>.*\ (\) '/etc/rc.d/init.d/functions
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/96/wKiom1XnN7XT01iYAAJdzlIkxDw466.jpg "title=" 6.jpg " alt= "Wkiom1xnn7xt01iyaajdzlikxdw466.jpg"/>
7, use echo to output a path, and then egrep find its path base name; Further use Egrep to remove its directory name
echo "/etc/rc.d/init.d/functions/" | Egrep ' [[: alnum:]]+/+$ '
echo "/etc/rc.d/init.d/functions" | Egrep '. */'
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/93/wKioL1XnOeWRg8PxAADduSP1ld8091.jpg "title=" 7.jpg " alt= "Wkiol1xnoewrg8pxaaddusp1ld8091.jpg"/>
18. Find the number between 1-255 in the result of ifconfig command execution
Ifconfig | Egrep-o ' \< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \> '
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/96/wKiom1XnN9CzskWtAAUm3CfCrfU283.jpg "title=" 8.jpg " alt= "Wkiom1xnn9czskwtaaum3cfcrfu283.jpg"/>
PS: The above summary may be insufficient or wrong place, please correct me.
This article is from the "money to buy sugar eat" blog, please be sure to keep this source http://pizimsn.blog.51cto.com/7002551/1691006
The grep of Linux Learning