In the course of learning Linux, you may have been exposed to a special symbol, such as "*", which is a wildcard symbol that represents 0 or more characters or numbers. The following Amin the special characters that are commonly used.
* represents 0 or more arbitrary characters.
[Email protected] ~]# ls-d test*test test1 test2 test3
? represents only one arbitrary character
[[email protected] ~]# Touch Testa[[email protected] ~]# touch Testb.txt[[email protected] ~]# ls-d test?test1 test2 te ST3 Testa
Whether it is a number or a letter, as long as it can be matched.
# This symbol indicates the meaning of the comment description in Linux, that is, the content behind the # Linux ignores.
[Email protected] ~]# abc=123 #aaaaa [[email protected] ~]# echo $ABC 123
\ A caret character that restores the following special symbol (for example, "*") to a normal character.
[[email protected] ~]# ls-d test\*ls: Unable to access test*: No file or directory
| The pipe character, which appears several times before, is the function of dropping the result of the preceding command to the command following the symbol. The following commands, which are mentioned here, are not available for all commands, and are commonly used for document operations such as Cat, less, head, tail, grep, cut, sort, WC, uniq, tee, tr, split, SED, awk, and so on, where G Rep, sed, awk are the tools that must be mastered for regular expressions, which are described in detail in the following sections.
[email protected] ~]# cat Testb.txt |wc-l0
wc-l used to calculate how many rows a document has . Here Amin suddenly listed a lot of unfamiliar commands to you, in fact, these commands in the daily processing document work is very practical, so Amin need to briefly introduce them, if you do not remember the relationship, later when used to check or directly with the man to query the help document.
Special Symbols $
$ In addition to the identifiers used in front of variables, there is another magical thing that is " ! "used together.
[[email protected] ~]# ls 1.txt
1.txt
[[email protected] ~]# ls!$
LS 1.txt
1.txt
! $ identifies the last variable in the previous command.
Special Symbols ;
Run two commands above the command in the middle with " ; "Separate
Special Symbols ~
User's home directory, if Root is/root, ordinary user is/home/username
Special Symbols &
Let the command run in the background and add it to the back of the command.
This is typically used when the command runs for a very long time.
> >> 2> 2>>
> Replace >> Append
2> Error Redirection
2>> Error Append redirect
Middle Bracket [ ]
The middle is a combination of characters that represents either of the intermediate characters.
See p164~167
$ In addition to the identifiers used in front of variables, there is a magical use that is combined with '! '.
[[email protected] ~]# ls testb.txttestb.txt[[email protected] ~]# ls! $ls testb.txttestb.txt
'!$ ' represents the last variable in the previous hit (in short, the last thing that appears in the previous command) For example, the top command is finally Testb.txt, so entering!$ under the current command represents Testb.txt.
; : Semicolon. Usually we are in a row to hit a command, and then enter the run, so you want to run two or two more commands in a row? You need to add a ";" between the commands.
[Email protected] ~]# ls-d test*; Touch test111; ls-d test*test test1 test2 test3 testa testb.txttest test1 test111 test2 test3 Testa Testb.txt
~ : User's home directory, if Root is/root, ordinary user is/home/username
[[Email protected] ~]# CD ~[[email protected] ~]# pwd/root[[email protected] ~]# su test[[email protected] root]$ CD ~[[em AIL protected] ~]$ pwd/home/test
& : If you want to put a command in the background, you need to add this symbol. This is typically used when the command runs for a very long time.
[[email protected] ~]# sleep &[1] 3260[[email protected] ~]# jobs[1]+ Running Sleep &
>>, 2> 2>> the forward symbol > and >> the meaning of substitution and append, and then there are two symbols that are here 2> and 2>> indicate error redirection and error append redirect respectively , when we run a command error, the error message will be output to the current screen, if you want to redirect to a text, you need to use 2> or 2>>
[[email protected] ~]# ls aaaals: Unable to access AAAA: No file or directory [1]+ done sleep 30[[email protected] ~]# ls AAAAls: cannot access aaaa: No file or directory [[email protected] ~]# ls aaaa 2>/tmp/error[[email protected] ~]# Cat/tmp/err orLS: unable to access AAAA: No file or directory [[email protected] ~]# ls aaaa 2>>/tmp/error[[email protected] ~]# Cat/tmp/error LS: Unable to access AAAA: No file or directory ls: cannot access aaaa: No file or directory
[] in brackets, the middle is a combination of characters, which represents either of the intermediate characters.
[Email protected] ~]# ls-d test*test test1 test111 test2 test3 testa testb.txt[[email protected] ~]# ls-d test[1- 3]test1 test2 test3[[email protected] ~]# ls-d test[1a3]test1 test3 testa[[email protected] ~]# ls-d test[0-9]test1 Test2 test3[[email protected] ~]# ls-d test[0-9a-z]test1 test2 test3 Testa
&& with the ||
A semicolon has just been mentioned above for the delimiter between multiple commands. There are also two special symbols that can be used in the middle of multiple commands, that is, "&&" and "| |" are all listed below:
Command1 ; Command2
Command1 && command2
Command1 || Command2
When using ";", Command2 will be executed regardless of whether Command1 is executed successfully;
When using "&&", only if the Command1 is executed successfully, Command2 will execute, otherwise command2 not execute;
When using "| |", the Command1 execution succeeds Command2 not execute, otherwise go to execute Command2, in short Command1 and Command2 always have a command to execute.
Before doing the experiment, Amin want to remove all the test*, but the deletion, but the prompt said that the authority is not enough, the following is the process of eliminating the problem Amin:
[[email protected] ~]# rm-rf test*rm: Cannot delete "Test2/test1": Insufficient permissions RM: Unable to delete "Test2/test3": Insufficient permissions RM: Unable to delete "Test2/test4": Insufficient authority [[email protected] ~]# ls test*test1 test3 test4[[email protected] ~]# lsattr test*----- A-------e-test2/test1----i--------e-test2/test3-------------e-test2/test4[[email protected] ~]# chattr-a Test2/test1[[email protected] ~]# chattr-i test2/test3[[email protected] ~]# rm-rf test*rm: Cannot delete "test2/ Test1 ": Insufficient permissions RM: Cannot delete" TEST2/TEST3 ": Insufficient permissions RM: Unable to delete" Test2/test4 ": Insufficient permissions [[email protected] ~]# ls test*test1 test3 test4[[email protected] ~]# ls-ld test*drwxrwxr-x 2 root root 4096 May 10 10:12 test2[[email protect Ed] ~]# ls-l test2/*-rw-r--r--1 root root 6 May 10 10:20 test2/test1-rw-r--r--1 root root 0 May 10 10:11 test 2/test3-rw-r--r--1 root root 0 May 10 10:12 test2/test4[[email protected] ~]# lsattr test2/*-------------e-tes T2/test1-------------e-test2/test3-------------e-tesT2/test4[[email protected] ~]# lsattr test2-------------e-test2/test1-------------e-test2/ Test3-------------e-test2/test4[[email protected] ~]# lsattr-d test2----i--------e-test2[[email Protected] ~]# chattr-i test2/[[email protected] ~]# rm-rf test2/
If you have done the same experiment with Amin before, I believe you will have the same problem. Next, Amin to explain the effects of the two special symbols "&&" and "| |" By doing experiments:
[[email protected] ~]# Touch test1 test3[[email protected] ~]# ls test2 && touch test2ls: Unable to access test2: No that file or directory [[EM AIL protected] ~]# ls test2ls: Cannot access test2: No file or directory [[email protected] ~]# ls test2 | | Touch TEST2LS: Unable to access test2: No file or directory [[email protected] ~]# ls test*test1 test2 test3
This article from "12350027" blog, declined reprint!
Special symbols in the shell