; Semicolon

Run commands in sequence

# ifdown eth0;ifup eth0

| Pipe

In regular expressions, means "or"

# echo "ooooee" |egrep '(oo|ee)'{2}   表示匹配 oooo 或者 eeee 的字符

The standard output of the preceding command is used as the standard input of the following command.

# ifconfig|grep eth0     表示ifconfig查出来的信息然后过滤出eth0的这一行

&

Put the command into the background for execution.

# mysqld_safe --user=mysql &        将MySQL放到后台启动

Represents standard output and standard error output.

# ifconfig &>/dev/null   将ifconfig执行得到的结果输出到/dev/null里面

&&

Execute the following command only if the preceding command returns 0.

# ls && echo "ok"  

||

Execute the following command only if the preceding command returns non-zero.

# lls || echo "ok" 

# Hash sign

#Indicates a comment

$#Indicates the number of positional parameters

# echo $#
0

${#variable_name}Indicates the length of the variable

# a='hello'
# echo ${#a}
5

${#variable_name[@]}Indicates the number of elements in the array

# a=(1 2 3)
# echo ${#a[@]}
3

! Exclamation mark

Invert the return value of a command or conditional expression.

# if ! [ 1 -lt 2 ]; then echo 'ok'; else echo 'no'; fi
ok

Execute a history command

# history 
1  ls
2  tail test1.txt
3  mysql -uroot -p123
4  ls /tmp/
5  cd /tmp/
[root@localhost ~]# !994
ls /tmp/
account.sql  data.sql  mysql.sock  t1.txt  t2.txt 

Execute external shell commands in vi or ftp.

For example: In vim, to execute a command, enter command-line mode, type the exclamation mark followed by the command to execute.

Indirect variable reference

For example: ${!a} ---- indirectly gets the value of b

$ Dollar sign

Get the value of a variable.

# a=10
# echo $a
10

In regular expressions, represents end of line.

egrep ':$' /etc/inittab 
egrep ‘^hello$'  file

> Greater-than sign

Output redirection

echo '123' >test.txt       表示将123 输入到文件test.txt中
Greater-than sign in conditional tests

< Less-than sign

Input redirection

Less-than sign in conditional tests

= Equals sign

Variable assignment- For example: set variable a=10

Equals sign in conditional tests- For example: [ a=b ] tests whether variable a equals b.

Numeric comparison ==- For example: (( a==20 )) tests whether variable a equals 20.

+ Plus sign

Plus sign in arithmetic operations - For example: 1+3

In regular expressions, one or more of the preceding character - For example: ab+c means matching one or more characters between ab and c.

>>

Output redirection append- For example: echo "123" >> test.txt appends 123 to the file test.txt.

<<

here document

For example:

# passwd <<end
> 123
> 123
> end

Change the password of user root.

- Minus sign

Minus sign in arithmetic operations - For example: 10-2

Command option - For example: ls -l

Previous working directory - For example: cd -

Represents a range in wildcards and regular expressions - For example: [a-z]

tar -cvf - /home | tar -xvf - 

Represents output stream or input stream.

Pipe the preceding output to the following command; the front compresses, the back decompresses.

'' Single quotes

Solve the problem of spaces in variable assignment.

For example: a='1 2'

Prevent shell substitution.

"" Double quotes

Solve the problem of spaces in variable assignment.

For example: a="1 2"

Prevent substitution of some shell characters; ineffective for $, !, etc.

`` Backticks, equivalent to $()

Command substitution

For example: you can set variable a=`ls`

% Percent sign

Modulo operation in arithmetic operations.

For example: echo $((100%10)) gives remainder 0 when 100 divided by 10.

In vi replacement operations, represents all lines. (In command-line mode, add % before replace to apply to all lines.)

For example: In command-line mode, enter :% s/D/d to replace all D in the text with d.

() Parentheses

Execute commands in a subshell; it inherits variables from the parent shell.

Encloses array elements.

For example: define an array.a=(1 2 3 4)

(()) Double parentheses

Arithmetic operations.

For example:echo $((10/2))The result is 5.

Integer comparison tests.

For example:(( 10>2 ))Test whether 10 is greater than 2.

[] Square brackets

In wildcards and regex, means matching any one character inside the brackets.

For example:[abc]Means matching any one of the characters a, b, or c.

Conditional test expression.

For example:[ -f /etc/passwd ]// Test whether it is a file.

Subscript brackets in arrays.

For example:echo ${a[0]}Means getting the value at index 0 in the array.

[[]] Double square brackets

String comparison tests.

For example: [[a=b]] is used for string comparison.

. Period (dot)

In regex, means any one character.

For example: a...b means matching a string with three characters between a and b.

Source script command in the current shell.

For example: ./test.sh executes the shell script test.sh in the current directory.

Represents the current directory.

For example: cd ./bgk enters the bgk directory under the current directory.

{} Curly braces

Wildcard expansion abc{1,2,3}

Represents a range in regular expressions.

For example: a{3} matches three a's.

for i in {1...10} loops over a specified range.

Anonymous function { cmd1;cmd2;cmd3;} &> /dev/null

The commands inside { } are executed in the current shell.

Note: In { }, there must be a space before the first command, and a semicolon after the subsequent command(s).

Encloses variable names.${abc}a

/ Forward slash

Division in arithmetic operations.

For example:echo $((10/2))The result is 5.

Root directory or path separator.

For example:cd /usr/local/Represents a path.

^

In wildcards, represents negation.

For example:[^abc] Means matching any character except a, b, or c.

In regular expressions, represents "starts with".

For example:

egrep ‘^hello$'  file