linux special characters and their functions

  • 2020-08-22 23:27:27
  • OfStack

1. A wildcard

The & # 63; Match a single character

* represents all characters

[abcd] matches any one character in []. 4 choose 1 [a - d]

[!abcd] matches characters that do not contain any one of the characters in []. [^ abcd]

2. Path correlation

~ user's home directory, super user /root, normal user /home

- Represents the path $OLDPWD control that the user was on the previous time (relative to the current path)

. Represents the current directory (the dot has many other meanings, not the table for the moment)

. Represents the previous level 1 directory

3. The quotation

"" what's inside a single quote is what's inside a single quote is 1 and it doesn't change. Output and processing are what you see is what you get.

Double quotes parse the commands and variables inside the quotes, then output and process

' 'Backquotes the equivalent of $() for the command

Note: If there is no special requirement, the string can be quoted in double quotes. Pure Numbers can be quoted without quotation marks.

4. Other

; Command terminator or delimiter.

# comments, for people to see. The machine ignores the root prompt.

| pipe passes standard output of one command as standard input to another command!

The $DOLLAR common user prompt, placed before the variable, represents the variable content


[root@chuanwen ~]# echo $PS1
[\u@\h \W]\$
[root@chuanwen~]# echo PS1
PS1
[root@chuanwen ~]# echo $PS1
[\u@\h \W]\$
[root@chuanwen~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@chuanwen~]# echo $OLDPWD
/root/test
\*   Make a meaningful character its own meaning 
{}   The sequence  {1..10} {a..z} {a,c,m}  seq
touch {1..10}.txt
[root@chuanwen ~]# cp /etc/ssh/sshd_config{,.ori}
[root@chuanwen ~]# ls /etc/ssh/sshd_config{,.ori}
/etc/ssh/sshd_config /etc/ssh/sshd_config.ori
[root@chuanwen~]# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori
&   Put the program into the background runtime, for example: /bin/sh /scripts/chuanwen.sh &

Supplement: Let's look at the linux special character usage


#  Well no.  (comments)
# The administrator  $ The average user 

 In the script 

#!/bin/bash #!/bin/sh
 Well Numbers also appear frequently 1 The beginning of a line, or after a full instruction, indicates that the symbol is followed by annotation text and will not be executed. 

# This line is comments.
echo "a = $a" # a = 0
 Because of this feature, when you temporarily do not want to execute a line of instructions, you simply add it at the beginning of the line  #  Will do. This is often used in writing. 
#echo "a = $a" # a = 0
 If it is used in an instruction, or if it is enclosed in quotation marks, or if it is followed by a backslash, then it becomes 1 General symbol, does not have the above special function. 

=======================================================================================

~  The account of  home  directory 

 Representative of the user  home  directory  cd ~  You can also simply add the name of an account after the symbol: cd ~ user Or think of it as a path 1 Part: ~/bin

~+  The current working directory, this symbol represents the current working directory, her and the built-in directive  pwd It's the same thing. 

# echo ~+/var/log

~-  The last working directory, this symbol represents the last working directory. 
# echo ~-/etc/httpd/logs

====================================================================================

;  A semicolon  (Command separator)

 in  shell  In the as " Continuous instruction " The symbol for the function is " A semicolon " . Take the following example: cd ~/backup ; mkdir startup ;cp ~/.* startup/.

=====================================================================================

;;  Continuous semicolons  (Terminator)

 Specialized in  case  The option to serve  Terminator  The role of. 
case "$fop" inhelp) echo "Usage: Command -help -version filename";;version) echo "version 0.1" ;;esac

=====================================================================================

.  The comma  (dot, That's the dot. )

 in  shell  It should be clear to the user, 1 a  dot  Represents the current directory, two  dot  Represents the upper directory. 
CDPATH=.:~:/home:/home/web:/var:/usr/local
 On the upside  CDPATH  After the equals sign  dot  Represents the meaning of the current directory. 
 If the file name is  dot  At the beginning, the file is a special file  ls  The instruction must be added  -a  The options are displayed. Besides that, in  regularexpression  , 1 a  dot  On behalf of the match 1 Characters. 

===================================================================================

'string'  Single quotes  (single quote)

 Content enclosed in single quotes is treated as a single 1 String. Representing a variable within quotation marks $ The symbol has no effect, that is to say, he is regarded as 1 General symbol handling to prevent any variable substitution. 
heyyou=homeecho '$heyyou' # We get $heyyou

"string"  Double quotation marks  (double quote)
 Content enclosed in double quotes is treated as single 1 String. It prevents wildcard extensions, but allows variable extensions. This is different from the way single arguments are handled. 
heyyou=homeecho "$heyyou" # We get home

`command`  It quotes  (backticks)

 In the preceding single and double quotation marks, the string is enclosed, but if the string is 1 What happens if I make a command column? The answer is no. And to deal with that, we have to do it in inverted commas. 
fdv=`date +%F`echo "Today $fdv"
 In inverted commas  date +%F  Will be treated as an instruction and the result of execution will be brought in  fdv  Variables. 

 ====================================================================================

,  comma  (comma ", the comma in punctuation )

 This notation is often used in operations as " The area lies between " Purposes. The following example 
#!/bin/bashlet "t1 = ((a = 5 + 3, b = 7 - 1, c = 15 / 3))"echo "t1= $t1, a = $a, b = $b"

====================================================================================

/  slash  (forward slash)

 In path representation, represents a directory. 
cd /etc/rc.dcd ../..cd /
 Usually a single 1 the  /  On behalf of  root  Meaning of the root directory; in 4 A symbol representing division in an operation. 
let "num1 = ((a = 10 / 2, b = 25 / 5))"
====================================================================================
\  Pour the slash 

 In interactive mode escape  Characters have several functions; In front of the command, there is cancellation  aliases The role of; If placed before a special symbol, the function of the special symbol disappears. Placed at the end of the instruction, indicating that the instruction is connected 1 Line. 
# type rmrm is aliased to `rm -i'# \rm ./*.log
 For example, I'm here  rm  Preorder  escape  Character, the effect is to temporarily cancel the alias function, will  rm  Instruction restore. 
# bkdir=/home# echo "Backup dir, \$bkdir = $bkdir"Backup dir,$bkdir = /home
 The above example  echo  Within the  \$bkdir . escape  will  $  The function of the variable has been disabled, so it will output  $bkdir And the first 2 a  $bkdir Output the contents of the variable  /home . 

=======================================================================================

|  The pipe  (pipeline)

 is  UNIX  Systematic, fundamental and important ideas. Links the standard output of the previous instruction as standard input for the next instruction. 
who | wc -l
 Make good use of this concept, to simplify  script  It's quite helpful. 

====================================================================================

!  Exclamation mark (negate or reverse)

 Usually it represents an anti-logic function, such as conditional detection, used by  !=  To represent the " Is not equal to "
if [ "$?" != 0 ]thenecho "Executes error"exit 1fi
 In regular expressions she ACTS as  " The logic "  The role of 
ls a[!0-9]
 In the above example, the representative shows except a0, a1 .... a9  These few files are other files. 

=====================================================================================

:  The colon 

 in  bash  This is 1 Built-in instructions: " Nothing " , but returns the status value  0 . 
:
echo $? #  Response for  0
: > f.[Math Processing Error] . Not only is the writing shorter, but the execution is much more efficient. 
 Sometimes, usages like the following also occur 
: ${HOSTNAME?} ${USER?} ${MAIL?}
 The purpose of this line is to check if these environment variables are set. If they are not set, an error message will be displayed with standard error. Checks like this one are similar if used  test  or  if This kind of practice, basically also can handle, but not as concise and efficient as the above example. 
 In addition to the above, there are 1 All places must use a colon 

 In the user's own HOME  In the directory  .bash_profile Or any similar function in the file, set about " The path " We use the colon to differentiate. 

====================================================================================

?  The question mark  (wild card)

 In filename extension (Filename expansion) The role played by the 1 An arbitrary character, but does not contain  null Characters. 
# ls a?a1
 Make good use of her characteristics, you can do more accurate filename matching. 

*  The asterisk  (wild card)
 A fairly common notation. In filename extension (Filename expansion) Above, she used to represent any character, including null  Characters. 
# ls a*a a1 access_log
 When you do an operation, it represents  " The multiplication " . 
let "fmult=2*3"
 Except for the built-in commands  let , as well as 1 An instruction about an operation expr The asterisk also serves here " The multiplication " The role of. But be careful how you use it. You have to put it in front of it escape  Characters. 
======================================================================================

**  The power operation 
 The two asterisks stand for operation  " To the power "  The meaning of. 
let "sus=2**3" echo "sus = $sus" # sus = 8
=====================================================================================

$  Money no. (dollar sign)
 Variable substitution (Variable Substitution) Is the symbol of. 
vrs=123 echo "vrs = $vrs" # vrs = 123
 In addition, in  Regular Expressions  Is defined as  " line "  The end of the  (end-of-line) . This is often used in grep , sed , awk  As well as  vim(vi)  In the middle. 
=====================================================================================

${}  A normal expression for a variable 
bash  right  ${}  A number of usages are defined. The following table columns are taken from the online instructions 

$*
$*  reference script The execution of reference variables, reference parameters of the algorithm and 1 The general instruction is the same, the instruction itself is 0 , then for 1 And so on. Reference variables are represented as follows: 
$0, $1, $2, $3, $4, $5, $6, $7, $8, $9, ${10}, ${11}.....
 Single-digit Numbers can be used directly, but more than two-digit Numbers must be used  {}  To enclose in symbols. 
$*  Is the symbol that represents all the referenced variables. Use double quotation marks as appropriate. 
echo "$*"
 There are 1 with  $*  A symbol having the same function but with slightly different utility and treatment. 

$@
$@  with  $*  They have the same function, but they have both 1 A difference. 
 symbol  $*  Treat all reference variables as 1 A whole. But the symbol  $@  The idea of extents for each referenced variable remains. 

$#
 This is also a symbol associated with reference variables, and what it does is it tells you what the total number of reference variables is. 
echo "$#"

$?  The status value  (status variable)
1 Generally speaking, UNIX(linux)  The process of the system to make a system call exit() To end. The return value is status Value. Is passed back to the parent process to check the execution status of the child process. 
1 If the general instruction program executes successfully, its return value is  0 ; Failure to  1 . 
tar cvfz dfbackup.tar.gz /home/user > /dev/nullecho"$?"$$
 Due to process ID Is the only 1 Of, so in the same 1 Time. There can be no repetition  PID . Sometimes, script Temporary files will need to be generated to hold the necessary data. And this script It could be the same 1 Time is used by users. In this case, fixed filenames are written in a way that makes them appear unreliable. Only by generating dynamic file names can we meet the requirements. symbol $$ It might meet that need. It represents the current shell  the  PID . 
echo "$HOSTNAME, $USER, $MAIL" > ftmp.$$
 Use it as the file name 1 In part, it can be avoided in the same 1 Time to generate the same file name overwrite phenomenon. 
ps:  Basically, the system will retrieve it and execute it  PID And then allocate it again as needed. so  script  Even temporary files are written with dynamic file names, if script  If it is not cleaned after execution, other problems may arise. 

====================================================================================

( )  Command group  (command group)
 The brackets 1 A string of consecutive instructions enclosed in brackets  shell  For example, it's called instruction groups. Here are some examples: (cd ~ ; vcgh=`pwd` ;echo $vcgh) , the instruction group has 1 A feature, shell Will be to produce subshell To execute this set of instructions. Therefore, the variables defined in it only apply to the instruction group itself. Let's look at an example 
# cat ftmp-01#!/bin/basha=fsh(a=incg ; echo -e "\n $a \n")echo $a#./ftmp-01incgfsh
 In addition to the above instruction groups, parentheses are also used in  array  The definition of a variable; Also used in other applications where you may need to add escape A situation in which characters can be used, as an expression. 

(( ))
 The function of this set of symbols is  let  Similar instructions, used in arithmetic operations, yes  bash  Built - in functionality. Therefore, in the implementation efficiency will be compared to the use  let Instructions are much better. 
#!/bin/bash(( a = 10 ))echo -e "inital value, a = $a\n"(( a++))echo "after a++, a = $a"

{ }  Curly braces  (Block of code)
 sometimes  script  It's going to come up, it's going to be sandwiched between curly braces 1 Paragraphs or paragraphs " A semicolon " Make a closing instruction or variable setting. 
# cat ftmp-02#!/bin/basha=fsh{a=inbc ; echo -e "\n $a \n"}echo $a#./ftmp-02inbcinbc
 This usage is very similar to the instruction group described above, except that it is in the current  shell  Execution does not occur  subshell . 
 Curly braces are also used in  " function "  The function of. In a broad sense, using curly braces alone ACTS like a function with no name specified 1 A. So let me write it this way  script It's also pretty good 1 Thing at a time. This approach can be streamlined, especially with respect to redirection of output and input  script  The complexity of. 
 In addition, there is another curly bracket 1 The usage is as follows 
{xx,yy,zz,...}
 This kind of combination of braces is often used for strings. Let's look at an example 
mkdir {userA,userB,userC}-{home,bin,data}
 We get  userA-home, userA-bin, userA-data, userB-home, userB-bin,userB-data, userC-home, userC-bin,userC-data , these directories. This set of symbols has a wide range of applicability. If it is put to good use, the reward is simplicity and efficiency. Take the following example 
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
 If it weren't for this usage, we'd have to write a few lines and repeat it a few times! 

[ ]  brackets 
 It is often used in process control to play the role of the judgment type. if [ "$?" != 0 ]thenecho "Executes error"exit1fi
 This symbol ACTS similarly in regular expressions  " The scope of "  or  " A collection of "  The role of 
rm -r 200[1234]
 In the above example, represents deletion  2001, 2002, 2003, 2004  And so on. 

[[  ]]
 This set of symbols is the same as the previous one  []  The notation, which basically does the same thing, but she allows it to be used directly in it  ||  with &&  Symbols such as logic. 
#!/bin/bashread akif [[ $ak > 5 || $ak< 9 ]]thenecho $akfi

==============================================================================

||  Logic symbol 
 You'll see this a lot. It represents  or  The symbol of logic. 

&&  Logic symbol 
 And you'll see this a lot. It represents  and  The symbol of logic. 

&  The background work 
 single 1 a &  Symbol, and placed at the end of the complete instruction column, that is, to put the instruction column in the background to work. 
tar cvfz data.tar.gz data > /dev/null&

\<...\>  Word boundary 
 This set of symbols is defined in a regular expression as " The border " The meaning of. For example, when we want to find  the  If we use this word 
grep the FileA
 You'll see, like  there  Words of this type will also be considered matching words. because  the  Even as  there the 1 Part. If we want to avoid such a situation, we must add  " The border "  The symbol of 
grep '\' FileA

+  A plus sign  (plus)
 In the formula, she is used to represent  " add " . 
expr 1 + 2 + 3
 In addition, in regular expressions, used to indicate " A number of " The meaning of the preceding character. 
# grep '10\+9' fileB109100910000910000931010009# When this symbol is used, it must be preceded by escape  Characters. 

-  A minus sign  (dash)
 In the formula, she is used to represent  " subtraction " . 
expr 10 - 2
 It is also an option symbol for system instructions. 
ls -expr 10 - 2
 in  GNU  Instruction if used separately  -  A symbol that represents the name of a file without any such addition " The standard input " The meaning of. This is a  GNU Common options for instructions. Such as the case 
tar xpvf -
 Here,  -  A symbol that represents reading data from standard input. 
 However, in the  cd  The instructions are more specific 
cd -
 This represents a change to the working directory " on 1 time " Working directory. 

===================================================================================
%  division  (Modulo)
 In an expression, used to represent  " division " . 
expr 10 % 2
 Also used in regular expressions about variables are the following 
${parameter%word}${parameter%%word}
1 a  %  Representing the shortest  word  Match, two means the longest  word  Matching. 

===============================================================================
=  The equal sign  (Equals)
 A symbol often seen when setting variables. 
vara=123echo " vara = $vara"
 Or like  PATH  Is even used for such purposes as operations or judgments. 

==  The equal sign  (Equals)
 It is often seen in the conditional judgment that represents  " Is equal to the "  The meaning of. 
if [ $vara == $varb ]
... The slightly 

!=  Is not equal to 
 It is often seen in the conditional judgment that represents  " Is not equal to "  The meaning of. 
if [ $vara != $varb ]
... The slightly 

^
 This symbol represents a row in a regular expression  " At the beginning "  Location, [] Also with the "!"( Exclamation point )1 Sample means "not" 

============================================================================
 The output / Input redirection 
>  >> < << :> &> 2&> 2<>>& >&2 

 File descriptor (File Descriptor) with 1 A number (usually 0-9 ) to indicate 1 A file. 
 Common file descriptors are as follows: 
 File descriptor     The name of the     Commonly used abbreviations    The default value 
  0     The standard input   stdin    The keyboard 
  1     The standard output   stdout    The screen 
  2    Standard error output  stderr    The screen 
 We're using it very simply < or > ", equivalent to use  0<  or  1> (More on this below). 
* cmd > file
 the cmd The output of the command is redirected to a file file In the. if file If it already exists, empty the file and use it bash the noclobber Option prevents overwriting of existing files. 
* cmd >> file
 the cmd The output of the command is redirected to a file file , if the file If it already exists, add the information to the original file. 
* cmd < file
 make cmd Command from the file Read in 
* cmd << text
 Reads input from the command line until 1 with text Same line ends. Unless the input is enclosed in quotation marks, this pattern does the same for the input shell Substitution. If you are using <<-  , ignores the following input at the beginning of the line tab And the end line could also be 1 The heap tab Coupled with the 1 with text See the following example for the same information. 
* cmd <<< word
 the word (Not a file word ) and the following line feed are provided as input cmd . 
* cmd <> file
 Put the file in read and write mode file Redirect to input, file file It can't be destroyed. Only if the application takes advantage of this 1 When it comes to features, it makes sense. 
* cmd >| file
 Function with > But even in Settings noclobber Time will also cover file File, note the use of | Rather than 1 Something from the book ! , currently only in csh Is still used in >! Achieve this 1 Function. 
: > filename   The file "filename" Truncated to 0 The length of the .#  If the file does not exist ,  So create 1 a 0 Length file ( with 'touch' The same effect ).
cmd >&n Send the output to the file descriptor n
cmd m>&n  The output   To the file descriptor m Redirect the information to the file descriptor n
cmd >&- Turn off standard output 
cmd <&n  Enter from the file descriptor n
cmd m<&n m From the file describes each n
cmd <&- Close standard input 
cmd <&n- Move the input file descriptor n Instead of copying it. (Need explanation) 
cmd >&n- Move the output file descriptor  n Instead of copying it. (Need explanation) 
 Note:  >& The file descriptor is actually copied, which makes cmd > file 2>&1 with cmd 2>&1 >file The effect is not 1 The sample. 

conclusion


Related articles: