First, homework (exercise) content:
1. Summarize the use of the commands involved in this course and show the relevant examples;
chmod
1. Order Explanation:
Change file permissions
Syntax structure:
chmod [OPTION] ... Mode[,mode] ... FILE ...
chmod [OPTION] ... Octal-mode FILE ...
chmod [OPTION] ...--reference=rfile FILE ...
Command options:
-r: The same permissions change for all files in the current directory and subdirectories (that is, they are changed in a recursive manner)
Three categories:
U:owner
G:group
O:other
A:all
Operation permissions for the specified category user:-
u-,g-,o-
Ug=,a=
To manipulate certain bit permissions for a certain type of user: +|-
u+,g+,o+
u-,g-,o-
Usage examples:
Modify 123.txt file A group has execute permissions:
chmod g+x/tmp/123.txt
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse337.tmp "border=" 0 "alt=" Wpse337.tmp "src=" http://s3.51cto.com/wyfs02/M00/72/58/wKioL1XhgnDDEteiAACgwV0zrKw259.jpg "height=" 136 "/>
Modify the 123.txt file property to 777:
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse338.tmp "border=" 0 "alt=" Wpse338.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/58/wKioL1XhgnGRpTlWAABrJLXXt4k065.jpg "height=" "/>"
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse339.tmp "border=" 0 "alt=" Wpse339.tmp "src=" Http://s3.51cto.com/wyfs02/M02/72/58/wKioL1XhgnHzJRJ5AAAPVp3oXiM332.jpg "height=" 6 "/>
Chown
1. Order Explanation:
Change the owner of a file
2. Command parameters:
chown [OPTION] ... [OWNER] [: [GROUP]] FILE ...
chown [OPTION] ...--reference=rfile FILE ...
3. Usage Examples:
Modify the owner of the/tmp/123.txt file, belonging to group Hzm Group of Hzm
Chown Hzm:hzm/tmp/123.txt
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse34a.tmp "border=" 0 "alt=" Wpse34a.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/58/wKioL1XhgnHRiDOmAABpq-_BpqU821.jpg "height=" "/>
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse34b.tmp "border=" 0 "alt=" Wpse34b.tmp "src=" Http://s3.51cto.com/wyfs02/M00/72/58/wKioL1XhgnGRpPepAAAO_SHEQOI639.jpg "height=" 6 "/>
Chgrp
1. Order interpretation;
Change the user group to which the file belongs
2. Command language
CHGRP [OPTION] ... GROUP FILE ...
CHGRP [OPTION] ...--reference=rfile FILE ...
3. Usage Examples:
Change the group of 123.txt files back to the root group:
CHGRP Root 123.txt
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse34c.tmp "border=" 0 "alt=" Wpse34c.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/58/wKioL1XhgnGgG4SLAABlgIZoYtg097.jpg "height=" "/>"
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse34d.tmp "border=" 0 "alt=" Wpse34d.tmp "src=" Http://s3.51cto.com/wyfs02/M02/72/58/wKioL1XhgnLi8Po2AAAOUznVIT4559.jpg "height=" 6 "/>
Umask
Catalog: 777-umask
Files: 666-umask
If the permissions of a certain class of users have permission to execute, it will automatically add 1 to its permission bit.
Umask umask
Set: Valid only for the current shell process;
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse34d.tmp "border=" 0 "alt=" Wpse34d.tmp "src=" Http://s3.51cto.com/wyfs02/M02/72/5C/wKiom1Xhgb3zjRA8AAAOUznVIT4957.jpg "height=" 6 "/>
2. Summarize basic regular expressions and extended regular expressions
Regular expression: Grep:global search REgular expression and Print out of the line.
Function: Text Search tool, according to user-specified "pattern" line to search for target text, print the matching line;
Pattern: The filter condition written by metacharacters and text characters of regular expressions;
Metacharacters: A character does not represent its literal meaning, but is used to denote a wildcard or control function;
Divided into two categories:
Basic Regular Expressions:
Character Matching:
. Match any single character
[] matches any single character within the specified range
[^] matches any single character outside the specified range
[0-9],[[:d igit:]],[^0-9],[^[:d igit:]]
[A-z],[[:lower:]]
[A-z],[[:upper:]]
[[: Space:]]
[[:p UNCT:]]
[0-9a-za-z],[[:alnum:]]
[A-za-z],[[:alpha:]]
Number of matches: A control is provided after the expected match character to express the number of times specified by the preceding character
* Any length, expressed 0 times, 1 or more times
. * Arbitrary length any character works in greedy mode
\? Match its preceding characters 0 or 1 times, dispensable
\+ 1 or more times means that the preceding character must not be there, or multiple times
\{m\} its left character exactly matches M-Times
\{m,n\} at least m times, up to N times
\{m,\} at least M-Times is unlimited
Position Anchor Nails:
^ Anchor Beginning
$ Anchor Line End
^.. $ to match the entire line of content with a pattern
^$ Matching Blank lines
Word anchoring:
\< anchor Word first \b
\> anchor ending \b
\<parttern\> matches the entire word that Partern can match
Group: \ (\)
\ (\) \1 match pattern from left to right, matched by the first opening parenthesis and the pattern in the corresponding closing parenthesis
\ (\) \2 match pattern from left to right, with the second opening parenthesis and the pattern in the corresponding closing parenthesis
Note: Grouping patterns, the characters that are matched during the last specific match, can be memorized by grep (stored in the built-in variables, which are \1,\2 ...), and therefore can also be referenced
To extend the regular expression:
Character Matching:
. Any length, expressed 0 times, 1 or more times
. * Arbitrary length any character works in greedy mode
[] matches any single character within the specified range
[^] matches any single character outside the specified range
Number of matches:
* Any time
? Match its preceding characters 0 or 1 times, dispensable
+
{m}
{m,}
{0,n}
Position Anchor Nails:
^
$
\< \>, \b
Group:
() \1
Or
A|b|c A or B or C
Or anything on both sides.
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse34e.tmp "border=" 0 "alt=" Wpse34e.tmp "src=" Http://s3.51cto.com/wyfs02/M02/72/5C/wKiom1XhgFbReUORAAAOzQ-C_ng791.jpg "height=" 6 "/>
3. Display the lines in the/etc/passwd file that end with bash
Egrep bash$/etc/passwd
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse34f.tmp "border=" 0 "alt=" Wpse34f.tmp "src=" http://s3.51cto.com/wyfs02/M00/72/5C/wKiom1XhgFaCUzo0AABDolkfBVQ187.jpg "height=" "/>"
4. Display the two-digit or three-digit number in the/etc/passwd file
Egrep--color=auto ' \<[0-9]{2,3}\> '/etc/passwd
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse360.tmp "border=" 0 "alt=" Wpse360.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/58/wKioL1XhgnKTZT7lAAHvtIZrJhA355.jpg "height=" 237 "/>
5. Displays the line with ' LISTEN ' followed by 0, one or more whitespace characters in the ' netstat-tan ' command result.
Netstat-tan | Egrep--color ' listen[[:space:]]+$ '
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse361.tmp "border=" 0 "alt=" Wpse361.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/5C/wKiom1XhgFew5WNrAAB13AIYTiA219.jpg "height=" "/>"
6. Add user bash, Testbash, basher, and Nologin user (Nologin the user's shell is/sbin/nologin), and then find the line in the/etc/passwd file that has the same user name as its shell name.
Egrep "\< ([[:alnum:]]+\>). *\1$"/etc/passwd | Cut-d:-F 1,7
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse362.tmp "border=" 0 "alt=" Wpse362.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/58/wKioL1XhgnOQOK2mAACAay9BeYQ591.jpg "height="/>
7. Display the default shell and UID of root, CentOS, or User1 user on the current system (please create these users beforehand, if not present)
Egrep "\<root|centos|user1\>"/etc/passwd | Cut-d:-F 3,7
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse363.tmp "border=" 0 "alt=" Wpse363.tmp "src=" http://s3.51cto.com/wyfs02/M00/72/58/wKioL1XhgnPRbdHkAABvj37x0nI236.jpg "height="/>
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
Egrep--color=auto ' \<[[:alnum:]]+\>\ (\) '/etc/rc.d/init.d/functions
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse373.tmp "border=" 0 "alt=" Wpse373.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/5C/wKiom1XhgFfALlaEAACQ6ztcVFA196.jpg "height=" 208 "/>
9, use echo to output a path, and then egrep find its path base name; Further use Egrep to remove its directory name
echo/etc/passwd/| Egrep-o "[[: alnum:]]+\/?$]--color
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse374.tmp "border=" 0 "alt=" Wpse374.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/5C/wKiom1XhgFjzhLOUAAB0isR6jv4968.jpg "height=" Bayi "/>
echo/etc/init.d/iptables/| Egrep-o "^\/.*\/"
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "title=" wpse375.tmp "border=" 0 "alt=" Wpse375.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/5C/wKiom1XhgFjyql2CAABHLtPdKkY161.jpg "height=" "/>"
10. Find the number between 1-255 in the result of ifconfig command execution
Ifconfig | Egrep ' \< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \> '--color
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/5F/wKiom1XhyQLDRj9yAAHZhM8Yjd8765.jpg "title=" LLL " alt= "Wkiom1xhyqldrj9yaahzhm8yjd8765.jpg"/>
20150827 after-school training assignments