first, the contents of this chapter
1, special characters
2, the filename wildcard character
3, logical operators and parentheses in multiple commands
4, the command is an expression
Note: This Linux system is RHEL5.3
two, Linux system special characters
1, double quotes
1],$ name= "Mary"
2],echo "Now time: ' Date '" # using inverted quotes to refer to the command output
3],# echo $NAME | grep jhon Alix Error Error
# echo $NAME | grep "Jhon Alix"
2, single quotes
1],$ name= "Mary"
2],echo "Now time: ' Date '" # using inverted quotes to refer to the command output
3],# echo $NAME | grep jhon Alix Error Error
# echo $NAME | grep ' Jhon Alix '
3, the command-quote counter quote
# ls-l ' Cat/etc/shells '
4, variable reference and command converter dollar sign
$ refers to a variable, just precede the variable name with "$"
# Ls-l $ (cat/etc/shells) # referencing command output using a command converter
5, anti-slash screen character
\ Mask The meaning of the special character itself.
# echo "Please pay \$15.50." #使用反斜线屏蔽输出字符串中的 $
three, the filename wildcard character
1,? represents any one character in the matching file name
# Ls-l A?
# Ls-l a??
2,* represents any string in the matching filename, which can be 0 to one character, or a string of long characters.
# ls-l *c
# ls-l Ee*c
# ls-l *c?
3,[] Character range matching, used to match a range of characters, which can be expressed as "-" the range of letters and numbers, or a combination of several characters
# ls-l [klsyz]* #以klsyz中任意字母开头的所有文件
# ls-l A*[CDE]?
4,[!] Exclude range matching, character combinations or alphanumeric ranges that appear in mismatched symbols
# ls-l [0-9][!0-9] #有两个字符, the first is a number, and the second is not a digital
four, logical operators and parentheses in multiple commands
1, logic or "| |"
Command1 | | Command2
Execute Command 1 First, if successful, skip command 2, if failed, execute command 2
# Mail-f/root/mbox | | echo "Permission Denied"
2, logic and "&&"
Command1 && Command2
Execute Command 1 First, if successful, execute command 2, and if it fails, skip command 2
# MV ~/rm.txt/&& echo "successfully moving Files"
3, brackets () and {}
(Command1; command2; Command3 ...)
{command1; command2; Command3 ...}
Execute the commands in parentheses sequentially until all the commands inside the brackets finish, and then return to execute the other commands.
Five, the command is an expression
1, "." A single character match, placed in the "//"
"/.i....../"
"/27210103../"
2, "*" single character or string repetition match, used to match one or more occurrences of individual characters or sequences of characters.
"/bo * *" can be matched, Bo, Boo, booooo ...
3, "^" line start match, used to indicate the line header position string or pattern in the match
"/^l/"
"/^2721010325/"
Regular expressions do not have a matching filename feature. Therefore, you cannot use the above mode directly on the Ls-l command, and you can leave the above mode to some filtering commands, such as the grep command: ls-l | Gerp/^l/
4, "$" line-end match, used to match string patterns at the end of each line of text, followed by matching strings
"/^ ... $l/" Match all lines with only 5 characters
"/love$/" matches the line at the end of love.
5, "\" backslash shield, such as shielding #,;, ', ',:, *, ^, $,?, [], etc
# expr 256 \* 256
"/\^\^\.txt/" Matching ^^.txt
6, "[]" matching character
"/[ll]ove/" matches love, Love
"/[^a-z]/" indicates that all letters are not matched
7, "\<", "\> Word first match, final match character
"/\<love/" matches all text with love as its first word
"/love\>/" matches all text ending with love
8, "x\{\}" repeat times match
"/M\{5\}/" matches text with 5 occurrences of M
Text with a "/M\{5,\}/" Match m occurrence of at least 5 times
"/M\{5,10\}/" matches text with 5 to 10 occurrences of M
9, using regular expressions in combination
"/^$/" matches a blank line
"/^.*$/" is used to match an entire line: fills the entire row with one character.
"/^[tt]he/" matches all rows beginning with the "or"
"/^[^tt]he/" excludes all rows with the beginning of the "or"
"/[0-9]\{1,3}\. [0-9]\{1,3}\. [0-9]\{1,3}\. [0-9]\{1,3}\/] matches an IP address
"/\<love\>/" Exact match love