25, Shell special symbol Cut command, sort_wc_uniq command, tee_tr_split command, Shell special symbol under
First, shell special symbol Cut command
Special symbols
*: Wildcard.
?: any one character.
#: Comment characters, add to command before command will not take effect.
\: de-semantic characters. The following special symbols (such as *) are reverted to normal characters. Example:
# ls-d 123\*
LS: Unable to access 123*: No file or directory
Cut command: Intercepts a field. Separated.
Format: # cut-d ' separator character ' [-CF] n,n is a number.
Available options:
-D: Specify delimited characters later, delimited characters to be enclosed in quotation marks, single or double quotation marks.
-C: followed by the first few characters. Use this parameter instead of-D and-F.
-F: The next section is followed by the number of blocks. Specifies the segment number.
Usage examples:
# cat/etc/passwd|cut-d ': '-F 1 |head-2
Root
Bin
# cat/etc/passwd|head-2|cut-d ': '-f 1-5
Root:x:0:0:root
Bin:x:1:1:bin
# cat/etc/p Sswd|cut-c 4 |head-2
T
:
Sort command: Used as a sort.
Format: # sort [-t delimiter] [-KN1,N2] [-nru]
-T: followed by delimited character, function and cut of the-D option.
-N: Sort using pure numbers.
-R: Reverse sort.
-U: to repeat.
-KN1,N2: Sorted by N1 interval to N2 interval, you can write-kn1 only, that is, sort N1 fields.
When no options are added, the ASCII values are compared backwards from the first character, and they are then output in ascending order.
Usage examples:
# head-n5/etc/passwd |SORT-T:-k2-n
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Root:x:0:0:root:/root:/bin/bash
# head-n3/etc/passwd |SORT-T:-k3,5-r
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Root:x:0:0:root:/root:/bin/bash
WC command: Used to count the number of lines, characters, or words of a document.
-L: Count rows
-M: Statistics of characters
-W: Number of statistical words
Usage examples:
# WC/ETC/PASSWD
921/etc/passwd
# wc-l/ETC/PASSWD
21/etc/passwd
# wc-m/ETC/PASSWD
921/etc/passwd
# wc-w/ETC/PASSWD
29/etc/passwd
# wc-m 1.txt
4 1.txt
# cat-a 1.txt $ has a newline character, so it is 4 characters.
l$
f$
Uniq command: To repeat. General and sort together, first sort, then go heavy.
-C: Counts the number of rows to repeat.
Example:
# Cat 1.txt
123
321
Abc
123
Abc
456
# sort 1.txt |uniq-c
1
2 123
1 321
1 456
2 ABC
Tee command: followed by the file name, function similar to redirect, but it is specific to a function, that is, the file is written to the following file, also displayed on the screen. This command is often used after a pipe break.
-A: Append.
Example:
# echo ' aaaaa ' |tee 1.txt
Aaaaa
# Cat 1.txt
Aaaaa
# echo ' aaaaabc ' |tee-a 1.txt
Aaaaabc
# Cat 1.txt
Aaaaa
Aaaaabc
TR command: Replace character, for character manipulation.
Common options:
-D: Deletes a character followed by the character to be deleted.
-S: Removes duplicate characters.
Used to turn lowercase letters into uppercase. such as TR ' [A-z] ' [A-z] '.
Example:
# echo ABCDE |tr ' a ' a '
Abcde
Split command: Cut the document.
Common options:
-B: Splits the document by size, with the default unit of byte.
-L: Cuts the document according to the number of rows.
Example:
# split-b passwd 123 You can specify a file name at the same time as the size, and the example is 123.
Iv. Special symbols (bottom)
$: Used as the identifier in front of the variable, can also be used in conjunction with,!$ regular inside represents the end of the line.
;: When two or more commands are run within a row, the symbols are added between the commands;.
~: User's home directory, root user's home directory for/root, ordinary users have to be/hone/username. A regular expression represents a match.
&: Used to place a command in the background and is typically used for long running times of the command. Example:
# & Sleep
[1] 1529
# jobs
[1]+ Run in Sleep &
2> or 2>>: Error redirection, error append redirect. Redirects a text.
Example:
# ls AAA
LS: Unable to access AAA: No file or directory
# ls AAA 2>/tmp/123
# cat/tmp/123
LS: Unable to access AAA: No file or directory
# ls AAA 2>>/tmp/123
# cat/tmp/123
LS: Unable to access AAA: No file or directory
LS: Unable to access AAA: No file or directory
Brackets []: a combination of characters in brackets, representing any of the character combinations, can be a range.
Example: # ls-d Test[1-3].txt
&&, | | :
# Command1; Command2
# Command1 && Command2
# Command1 | | Command2
When used, the Command2 is executed regardless of whether or not the Command1 is performing successfully.
With &&, only Command1 execution succeeds, Command2 executes, otherwise Command2 does not execute.
Use | | , Command1 execution succeeds, Command2 does not execute, otherwise execution command2, that is, Command1 and Command2 always have a command to execute. Example:
# Touch Test3;touch Test1
# ls
Test1 Test3
# ls test2 && touch test2
LS: Unable to access test2: No file or directory
# ls Test2 | | Touch Test2
LS: Unable to access test2: No file or directory
# ls test*
Test1 test2 Test3
25. Shell special Symbol Cut command, sort_wc_uniq command, Tee_tr_split command,