- Shell Special Symbol Cut command
Special symbols
* wildcard characters, any of any character
? Any one character
# comment Characters
\ de-Semantic characters
C=\ $a \ $b
Echo $c
| Pipe character
Cat 1.txt |less
Cat 1.txt |more
Cut intercept string
Show first 2 rows
CAT/ETC/PASSWD |head-2
Cut ":" First paragraph cut-d ":"-F 1
Cut two: cut-d ":"-F
ETC/PASSWD the first two lines, cut 1 to three segments with a colon
CAT/ETC/PASSWD |head-2 |cut-d ":"-F 1-3
[Email protected]:~# cat/etc/passwd |head-2 |cut-d ":"-F
Root:x
Bin:x
[Email protected]:~# cat/etc/passwd |head-2 |cut-d ":"-F 1-2
Root:x
Bin:x
[Email protected]:~# cat/etc/passwd |head-2 |cut-d ":"-F 1-3
root:x:0
Bin:x:1
CUT specifies the number of characters:
Cut-c 4
[Email protected]:~# cat/etc/passwd |head-2 |cut-c 4
T
:
Sort order-N numerically sort-R reverse order
SORT/ETC/PASSWD alphabetically by first letter
Fetch file content first 10 lines write to 1.txt
HEAD/ETC/PASSWD > 1.txt
Vim 1.txt Editor, write several special symbols * "<>";?
Sort 1.txt
The default is the special symbol in front, then the number, alphabetical order, the * number in the back of the line
Sort-n 1.txt
will be sorted numerically, letters and special symbols will be considered to be 0
SORT-NR 1.txt Reverse order the largest in the front
Sort-t-kn1/-kn2 delimiter Specifies the order of the paragraphs
Wc-l count rows
Wc-m Statistic character Count
[Email protected]:~# wc-l 1.txt
1.txt
[Email protected]:~# wc-m 1.txt
432 1.txt
[Email protected]:~# vim 2.txt
Input
Abc
123
: Wq
[Email protected]:~# wc-m 2.txt
8 2.txt
[Email protected]:~# cat-a 2.txt
abc$
123$
Each row has a newline character $
Wc-w 2.txt counts the number of words, which are distinguished by whitespace characters
[Email protected]:~# wc-w 2.txt
2 2.txt
Uniq (unique) 2.txt to repeat
[Email protected]:~# uniq 3.txt
1
222
333
4
56476
[Email protected]:~# cat 3.txt
1
1
1
222
333
4
4
56476
Sort first, then count.
Number of repetitions of statistics:
Sort 2.txt |uniq-c
[Email protected]:~# sort 3.txt |uniq-c
3 1
1 222
1 333
2 4
1 56476
Piping |tee and > Similar, redirects are also displayed on the screen
Role: Redirect and print to the screen
[Email protected]:~# sort 3.txt |uniq-c > A.txt
[Email protected]:~# cat A.txt
3 1
1 222
1 333
2 4
1 56476
[Email protected]:~# sort 3.txt |uniq-c |tee b.txt
3 1
1 222
1 333
2 4
1 56476
[Email protected]:~# cat B.txt
3 1
1 222
1 333
2 4
1 56476
[Email protected]:~#
Both ">" and "|tee" can be written to a file
Empty a.txt
>a.txt
>> additional, |tee-a can also be added
|tee-a Append
[Email protected]:~# sort 3.txt |uniq-c |tee-a b.txt
TR replacement character, tr ' a ' B ', case replacement TR ' [A-z] ' [A-z] '
Change XB to uppercase XB
[Email protected]:~# echo ' xiaobo ' |tr ' [XB] ' [XB] '
Xiaobo
change x to X individually
[Email protected]:~# echo ' Xiaobo ' |tr ' x ' x '
Xiaobo
Change the lowercase letter to uppercase
[Email protected]:~# echo ' xiaobo ' |tr ' [A-z] ' [A-z] '
Xiaobo
Change all the letters to 1.
[Email protected]:~# echo ' xiaobo ' |tr ' [A-z] ' 1 '
111111
Log file 800G words, reading difficulties, can be cut
Append all the Conf files in the ETC to the A.txt file.
[Email protected]:~# find/etc/-type f-name "*conf"-exec Cat {} >> a.txt \;
[Email protected]:~# du-sh a.txt
1.1M A.txt
Cutting files A.txt, 100K per file
[Email protected]:~# du-sh a.txt
464K A.txt
[Email protected]:~# split-b 100k a.txt
[Email protected]:~# ls
A.txt xaa xab xac xad xae
Specify a filename prefix
[Email protected]:~# rm-f x*
[Email protected]:~# split-b 100K a.txt ABC
[Email protected]:~# ls
ABCAA abcab ABCAC Abcad abcae a.txt
Cut one file per 1000 lines
[Email protected]:~# split-l a.txt
[Email protected]:~# ls
A.txt xaa xab xac xad xae xaf xag xah xai xaj xak xal xam
[Email protected]:~# wc-l a.txt
12764 A.txt
$ variable prefix,! $ combination, regular inside means end of line
Multiple commands are written to one line, separated by semicolons.
~ User home directory, followed by regular expression to indicate match
& put the command behind the command and throw it backstage.
Write redirect >, Chase redirect >> &> (bad redirect and correct redirect output)
[] One of the specified characters, [0-9],[A-ZA-Z],[ABC]
|| and &&, used between commands
[[email protected] ~]# for i in ' SEQ 1 10 '
> Do
> Echo $i
> Done
Multiple commands separated by semicolons
[[email protected] ~]# for i in ' seq 1 ';d o echo $i; Done
|| Represents or, if the previous command executes successfully, the subsequent command is not executed, and if the preceding command does not succeed, continue with the following command
[[email protected] ~]# ls la.txt| | Wc-l 1.txt
LS: Unable to access la.txt: No file or directory
0 1.txt
[[email protected] ~]# Wc-l 1.txt | | LS La.txt
0 1.txt
&& if the previous command succeeds, the following command is executed, and if the previous command fails, the subsequent command is not executed.
If there is a fake, it will not follow.
[[email protected] ~]# ls la.txt && wc-l 1.txt
LS: Unable to access la.txt: No file or directory
[Email protected] ~]# wc-l 1.txt && ls la.txt
0 1.txt
LS: Unable to access la.txt: No file or directory
Determine if a directory exists
[-D Xiaobo] | | mkdir Xiaobo
If the Xiaobo directory does not exist, the directory is created.
If the directory exists, the directory is not created.
Shell special symbol Cut Command sort_wc_uniq command tee_tr_split command shell special symbol