One, Shell special character _cut command
De-Semantic characters:
[[email protected] ~]# c=\ $a \ $b//And #c = ' $a $b ' effect
[Email protected] ~]# echo $c
$a $b
Pipe character
Cut split
[Email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-F 1//Take the first paragraph
Root
Bin
[Email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-f +//Take 1th, 2nd paragraph
Root:x
Bin:x
[[email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-f 1-3//Take 1-3 segment
root:x:0
Bin:x:1
[email protected] ~]# cat/etc/passwd |
head-2 |
cut-c 4//-c, specifying the first few characters T |
Second, Sort_wc_uniq command
Sort sorts
[[email protected] ~]# SORT/ETC/PASSWD//General no special symbols according to a B c D e 26 alphabetical order
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
Dbus:x:81:81:system message Bus:/:/sbin/nologin
Ftp:x:14:50:ftp User:/var/ftp:/sbin/nologin
Games:x:12:100:games:/usr/games:/sbin/nologin
Halt:x:7:0:halt:/sbin:/sbin/halt
Hll:x:1001:1002::/home/hll:/bin/bash
[[email protected] ~]# sort filename//file with special symbols, numbers, first-line special symbols, numbers, letters
(
[
}
11
345
88
Aadgg
bbbb
Dgfggf
Sort-n Options
[[email protected] ~]# sort-n filename//-n option to sort by numbers, and to recognize special symbols and letters as 0
(
[
}
Aadgg
bbbb
Dgfggf
11
88
345
SORT-NR filename,-r option, reverse sort, max in front, smallest in back
Commands #wc-l//Count rows
[[email protected] ~]# wc-l 2.txt//Statistics 2.txt file line number
2.txt
#wc-m//Statistics character count command
[[email protected] ~]# wc-m 2.txt//Statistics 2.txt file character count
2.txt
#cat-a 2.txt//cat-a can see all characters including hidden, and you can see a line break after each row of characters
#wc-W 2.txt//Number of statistical words
[Email protected] ~]# wc-w 2.txt
2.txt
#uniq//To repeat, but to sort before going to the heavy
Can be sorted first, using #sort 2.txt, and then #sort 2.txt |uniq
Iii. Tee_tr_split Order
Tee and > similar, redirect while still on screen display
Empty a file command:#> 2.txt//empty 2.txt file contents
Sort 2.txt |uniq-c |tee 4.txt//2.txt files are redirected to the 4.txt file, the role of |tee is to redirect, the results of the pipeline before printing on the screen
#sort 2.txt |uniq-c |tee-a 4.txt//tee-a is append
The TR command is used to replace characters
[[email protected] ~]# echo "Linux" |tr ' [ln] ' [ln] '//replace ln with LN
Linux
[[email protected] ~]# echo "linux" |tr ' ln '//or can be written like this
Linux
[[email protected] ~]# echo "Linux" |tr ' [A-z] ' [A-z] '//can specify range
Linux
Split cut
#split-B 100M bigfile//-b option, specify the cut file size, do not write unit 1000 after the default unit is byte
#split-l bigfile//-l option to specify the number of cut file lines
#find/etc/-type f-name "*conf"-exec Cat {} >> 3.txt \; Find the. conf file under/etc and append it to 3.txt
#split-B 3.txt//Specify a cut file size of 1000 bytes
[[email protected] ~]# split-b 100K 3.txt ABC//Specify cut file prefix to ABC
[[email protected] ~]# ls
2.txt 4.txt abcab 3.txt ABCAA ABCAC
#split-L 3.txt//Cut 1000 rows
Four, the shell special symbol under
[[email protected] ~]# for I in seq 1 10
//Execute multiple commands
Do
Echo $i
Done
1
2
3
4
5
6
7
8
9
10
[[email protected] ~]# for I seq 1 10
in; does echo $i; done//Use the UP History command to list multiple commands separated by semicolons
[email protected] ~]# ls 3.txt; Wc-l 2.txt//Two command to perform an intermediate plus semicolon
3.txt
2.txt
Correct redirection will overwrite the previous file
> Chase weighted correct output
2> Output Error Content redirection
2>> Append the error message redirect
&> output the correct error content to a file
[] One of the specified characters, [0-9], [a-za-z], [ABC]
|| To denote or mean in the shell.
#ls 1.txt | | Wc-l 2.txt//| | Indicates that the second command is not executed when the first command executes successfully, and the second is executed if the first one is unsuccessful.
#ls 1.txt && wc-l 2.txt//&& indicates that the previous command executed successfully before executing the subsequent command
#[-d ABCD] | | mkdir ABCD//Determine if the ABCD directory exists, if it is not created, if it does not exist, create
Shell special Symbol Cut command, sort_wc_uniq command tee_tr_split command