special symbols
-
* any character
-
? any character
-
comment character
Indicates that this command does not take effect, to explain
-
\ escape character
[root@localhost ~]# a=1
[root@localhost ~]# b=2
[root@localhost ~]# c=$a$b
[root@localhost ~]# echo $c
12
[root@localhost ~]# c=\$a\$b
[root@localhost ~]# echo $c
$a$b
[root@localhost ~]#
-
| Pipe character, several commands related to pipes
-
cut command: intercept string
-
cat /etc/passwd |cut -d ":" -f 1,2
-d delimiter
-f specifies the segment number
-c specifies the number of characters, you can't use -d and -f when using it.
[root@localhost ~]# cat /etc/passwd | head
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost ~]# cat /etc/passwd |cut -d ":" -f 1,2
root:x
bin:x
daemon:x
adm:x
lp:x
sync:x
shutdown:x
halt:x
mail:x
operator:x
games:x
ftp:x
nobody:x
systemd-bus-proxy:x
systemd-network:x
dbus:x
polkitd:x
tss:x
postfix:x
sshd:x
chrony:x
user1:x
user2:x
user3:x
[root@localhost ~]#
-
sort : sort command, the default is in Asma order
[root@localhost ~]# sort 1.txt
>
.
@
《
111n
1.txt
*2
222333
222444
222555
222aaaa
2.txt
333333
4444444
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
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
ls: 无法访问asffsfs.txt: 没有那个文件或目录
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologi
root:x:0:0:root:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
[root@localhost ~]#
-n sort by number, default letters and special symbols will be considered as 0
[root@localhost ~]# sort -n 1.txt
>
.
@
《
*2
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
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
ls: 无法访问asffsfs.txt: 没有那个文件或目录
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologi
root:x:0:0:root:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
1.txt
2.txt
111n
222aaaa
222333
222444
222555
333333
4444444
[root@localhost ~]#
-r reverse order, reverse to Asma
[root@localhost ~]# sort -r 1.txt
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologi
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
ls: 无法访问asffsfs.txt: 没有那个文件或目录
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
daemon:x:2:2:daemon:/sbin:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
4444444
333333
2.txt
222aaaa
222555
222444
222333
*2
1.txt
111n
《
@
.
>
[root@localhost ~]#
-t Delimiter. -kn1/-kn1,n2
-
wc -l : count lines command
[root@localhost ~]# wc -l 1.txt
25 1.txt
wc -m : count the number of characters
[root@localhost ~]# wc -m 1.txt
487 1.txt
wc -w : statistical words, separated by blank characters
[root@localhost ~]# wc -w 1.txt
27 1.txt
[root@localhost ~]#
-
uniq deduplication requires adjacent duplicate words to be removed, so generally sort first and then remove duplicates sort 2.txt |uniq -c
-c count duplicate lines
tee is similar to >
Visual redirection
[root@localhost ~]# sort 1.txt > a.txt
[root@localhost ~]# cat a.txt
>
.
@
《
111n
1.txt
*2
222333
222444
222555
222aaaa
2.txt
333333
4444444
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
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
ls: 无法访问asffsfs.txt: 没有那个文件或目录
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologi
root:x:0:0:root:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
[root@localhost ~]# sort 1.txt |tee a.txt
>
.
@
《
111n
1.txt
*2
222333
222444
222555
222aaaa
2.txt
333333
4444444
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
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
ls: 无法访问asffsfs.txt: 没有那个文件或目录
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologi
root:x:0:0:root:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
[root@localhost ~]#
-
|tee -a Visual append redirection
-
tr replace character
[root@localhost ~]# echo "aminglinux" |tr 'a' 'A'
Aminglinux
[root@localhost ~]# echo "aminglinux" |tr '[anx]' '[ANX]'
AmiNgliNuX
[root@localhost ~]# echo "aminglinux" |tr '[a-z]' '[A-Z]'
AMINGLINUX
split
-
-b specifies the split size: split -b 100M bigfile filename (the default display is bytes if the unit is not written)
-
-l specifies the number of lines to split the file: split -l 1000 bigfile filename
shell special symbols
-
$variable prefix, !$ combination, which means the end of the line
-
; Write multiple commands on one line, separated by semicolons
-
~ User home directory, followed by a regular expression that represents a match
-
& put it after the command, it will drop the command to the background
-
> >> 2> 2>> &>
-
[] specifies one of the characters
-
|| and &&, used between commands
- || Or means
- &&
- ||
If the command prompt before || is successful, the command after || will not be executed, and if the previous command is unsuccessful, the command after || will be executed.
[root@localhost ~]# ls 1a.txt ; wc -l 1.txt
ls: 无法访问1a.txt: 没有那个文件或目录
25 1.txt
[root@localhost ~]# ls 1a.txt || wc -l 1.txt
ls: 无法访问1a.txt: 没有那个文件或目录
25 1.txt
[root@localhost ~]# ls 1.txt || wc -l 1.txt
1.txt
[root@localhost ~]#
- &&
If the previous command is executed successfully, the following command will be executed. If the previous command is wrong, the latter command will not be executed.
[root@localhost ~]# ls 1.txt && wc -l 1.txt
1.txt
25 1.txt
[root@localhost ~]# ls 1a.txt && wc -l 1.txt
ls: 无法访问1a.txt: 没有那个文件或目录
[root@localhost ~]#