Chapter 1 Reviewing Special Symbols
| #管道符,或者(正则)
> #输出重定向
>> #输出追加重定向
< #输入重定向 << #追加输入重定向 ~ #当前用户家目录 `` $() #引用命令被执行后的结果 $ #以。。。结尾(正则) ^ #以。。。开头(正则) * #匹配全部字符,通配符 ? #任意一个字符,通配符 # #注释 & #让程序或脚本切换到后台执行 && #并且 同时成立 [] #表示一个范围(正则,通配符) {} #产生一个序列(通配符) . #当前目录的硬链接 .. #上级目录的硬链接
Chapter 2 Wildcards
He is the built-in wildcard function of the shell.
Those who have used DOS should know it well, and it is also very commonly used.
Wildcards, referring to strings containing these characters "?", "*", "[", {}
Wildcard meaning ===> match file name
symbol | effect |
---|---|
* | matches any string/text, including the empty string; * stands for any character (0 or more) ls file * |
? | Match any character (when not in brackets)? Represents one character ls file 0 |
[abcd] | matches any character in abcd |
[a-z] | Indicates the range a to z, the meaning of the range [] matches any character in the brackets ls file 0 |
{..} | Represents a generated sequence. separated by commas and no spaces |
Replenish | |
[!abcd] | Or [^abcd] means not, means it does not match any character in the brackets |
2.1 Detailed explanation of wildcards
2.1.1 "represents any string"
ls .log .txt
2.1.2 ? any one character
2.1.3 [abcd] means that any character in the brackets is matched
2.1.4 Wildcards are used to find files (match file names)
2.1.5 {}Generate sequence
2.1.6 Backup using {}
2.1.7 [^abcd] !^ means not, negate
Not commonly used, just understand
2.2 Difference between [] and {}
[] can only be used to find a file
{} is used to find a file, or create a file, generate a sequence
2.3 Wildcard Summary
Wildcard meaning ===> match file name
symbol | effect | |
---|---|---|
* | matches any string/text, including the empty string; represents any character (0 or more) ls file | |
? | Match any character (when not in brackets)? Represents one character ls file 0 | |
[abcd] | matches any character in abcd | |
[a-z] | Indicates the range a to z, the meaning of the range [] matches any character in the brackets ls file 0 | |
{..} | Represents a generated sequence. separated by commas and no spaces | |
Replenish | ||
[!abcd] | Or [^abcd] means not, means it does not match any character in the brackets |
Chapter 3 Special Symbols
3.1 Pipe section
命令1|命令2 ###管道符号,传递的时普通的文本,字符串,来自于前一个命令。
|xargs ###管道符号,与xargs传递的是把文本,字符串变成了文件名
3.2 Directory Structure
. #当前目录(或“任意一个字符”正则)
.. #当前目录的上一级目录
3.3 Redirect symbols
> #输出重定向,会清空原文内容,然后在向文件里面追加内容
>> #追加输出重定向,追加到文件的最后一行
< #输入重定向tr xargs
<< #cat 用来给文件追加多行文本
For example: >/dev/null 2>&1
3.4 Uncategorized special symbols
3.4.1 # indicates a comment
Linux will ignore him, show it to the operation and maintenance personnel, and explain it.
3.4.2 $ Refers to a variable to the value of a variable or a normal user's command prompt
1, shell
$variable ===> take the contents of the variable
2, awk
$take column $number
3, the command prompt of ordinary users
[ root@chensiqi ~]$
3.4.3 `` (below esc) backticks quote the result of the command, equivalent to $()
3.4.4 ; Separate multiple commands, there is no logical relationship, just execute step by step.
1,shell
pwd;pwd;pwd;hostname
is equivalent to
pwd
pwd
pwd
hostname
2,sed
[root@chensiqi ~]$ seq 100 | sed -n '20p;50p;100p'
20
50
100
3.4.5 - (cd - ;su -)
- cd - ###Return to the last working directory, return to the last location
- su - ### switch user, reload environment variables
3.4.6 ~ current user's home directory, home
[ root@chensiqi ~]$ cd ~
will directly return the home directory of the current user
3.4.7 / root or path separator
3.4.8 Escape symbols or mask aliases
. #(正则里代表任意一个字符)
\. #只代表一个点的符号
3.4.9! means not
1, means non-
2, means force
vi/vim
vi force quit (q!)
3.4.10 && means and
Pay special attention to
the && symbol, only the current command on the current side will execute the following command successfully.
Chapter 4 Common Special Symbols and Wildcards
wildcard | meaning |
---|---|
* | Represents any (0 or more) characters |
? | Represents any 1 character |
[abcd] | Match any character in brackets |
{} | The middle is command block combination or content generation |
special symbols | meaning |
;semicolon | Separator for consecutive different commands |
# | Configuration file comments |
| | Pipeline, passing the result of the previous command to the next command to continue processing |
~ | cd ~ the current user's home directory |
- | cd - the directory where the user was last, controlled by the variable OLDPWD; su - switch the user's system environment |
.. | upper level directory |
. | Current directory (three ways to write the current directory: ls or ls . or ls ./) |
$ | The symbol $OLDPWD that needs to be added before the variable; the command prompt of ordinary users |
/ | root; path separator |
\ | Mask system aliases; escape characters; |
> | output redirection |
>> | output append redirection |
< | input redirection |
<< | Enter append redirect |
‘’ | Single quotation marks, no variable substitution function, what you see is what you get when outputting |
“” | Double quotes, with variable substitution function, parsing variable output |
`` | Backticks (backticks), `` is a command in the middle, which will be executed first, equivalent to $() |
! | "NOT" in logical operations; force quit in vi/vim; ! + letter recalls the most recent command starting with this letter; ! ! Use the most recent command |
&& | When the previous command is executed successfully, execute the next command |
double pipe character | When the execution of the previous command fails, execute the next command |
Chapter 5 The Difference Between Single, Double, and Unquoted Quotes
-
Single quote: what you see is what you get.
-
Double quotation marks: Parse special symbols, special symbols have the original special meaning
-
Unquoted: special, wildcards are supported