1、命令排序:
1.1、 分号";",在同一行顺序执行多个命令,每个命令用;隔开;后面的命令不依赖前面命令是否执行成功
[root@centos6 test2]
aa bb.txt cc.sh
2019年 11月 25日 星期一 17:02:54 CST
[root@centos6 test2]
1.2、 && 与 ||
1.2.1、&& 连接两个命令,当第一个命令执行成功后,第二个命令执行,否则第二个命令不执行。
[root@centos6 test2]
111
root@centos6 test2]
dd.txt
111
[root@centos6 test2]
[root@centos6 test2]
ls: 无法访问ee.txt: 没有那个文件或目录
[root@centos6 test2]
1.2.2、 || 连接两个命令,当第一个命令执行失败后,第二个命令执行,否则第二个命令不执行。
[root@centos6 test2]
ls: 无法访问ee.txt: 没有那个文件或目录
cat: ee.txt: 没有那个文件或目录
[root@centos6 test2]
[root@centos6 test2]
ls: 无法访问ee.txt: 没有那个文件或目录
[root@centos6 test2]
[root@centos6 test2]
ee.txt
1.2.3、 && 和 || 同时使用:如果第一个命令执行成功,则执行&&后的命令;如果第一命令执行失败,则执行 || 后的命令
[root@centos6 test2]
PING 192.168.24.130 (192.168.24.130) 56(84) bytes of data.
64 bytes from 192.168.24.130: icmp_seq=1 ttl=64 time=0.286 ms
--- 192.168.24.130 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.286/0.286/0.286/0.000 ms
[root@centos6 test2]
[root@centos6 test2]
PING 192.168.24.131 (192.168.24.131) 56(84) bytes of data.
From 192.168.24.129 icmp_seq=1 Destination Host Unreachable
--- 192.168.24.131 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 3001ms
[root@centos6 test2]
..ok
[root@centos6 test2]
[root@centos6 test2]
..fail
2、通配符(元字符)
2.1、* 匹配任意多个字符
[root@centos6 test2]
-rw-r--r--. 1 root root 0 11月 25 17:02 bb.txt
-rw-r--r--. 1 root root 4 11月 25 17:05 dd.txt
-rw-r--r--. 1 root root 0 11月 25 17:10 ee.txt
-rw-r--r--. 1 root root 0 11月 25 17:21 fff.txt
-rw-r--r--. 1 root root 0 11月 25 17:21 k.txt
2.2、? 匹配任意一个字符
[root@centos6 test2]
-rw-r--r--. 1 root root 0 11月 25 17:02 bb.txt
-rw-r--r--. 1 root root 4 11月 25 17:05 dd.txt
-rw-r--r--. 1 root root 0 11月 25 17:10 ee.txt
[root@centos6 test2]
[root@centos6 test2]
-rw-r--r--. 1 root root 0 11月 25 17:21 k.txt
2.3、[] 匹配括号中任意一个字符
[root@centos6 test2]
-rw-r--r--. 1 root root 0 11月 25 17:02 bb.txt
-rw-r--r--. 1 root root 4 11月 25 17:05 dd.txt
-rw-r--r--. 1 root root 0 11月 25 17:10 ee.txt
2.4、() 在子shell中执行
[root@centos6 test2]
dog duanyi hack jmz qiaofeng sx test1.txt test2.txt testuser1 testuser2 tony
[root@centos6 home]
[root@centos6 home]
[root@centos6 home]
/home
[root@centos6 home]
[root@centos6 home]
/root/test2
[root@centos6 test2]
[root@centos6 test2]
dog duanyi hack jmz qiaofeng sx test1.txt test2.txt testuser1 testuser2 tony
[root@centos6 test2]
[root@centos6 test2]
/root/test2
[root@centos6 test2]
2.5、{} 集合
[root@centos6 test2]
-rw-r--r--. 1 root root 0 11月 25 17:21 fff.txt
-rw-r--r--. 1 root root 0 11月 25 17:21 k.txt
[root@centos7 ddd]
[root@centos7 ddd]
[root@centos7 ddd]
总用量 0
-rw-r--r--. 1 root root 0 12月 10 20:38 test10.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test1.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test2.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test3.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test4.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test5.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test6.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test7.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test8.txt
-rw-r--r--. 1 root root 0 12月 10 20:38 test9.txt
[root@centos7 ddd]
2.6、\ 转义符,让特殊符号回归普通字符
[root@centos6 test2]
aa bb.txt cc.sh dd.txt ee.txt fff.txt k.txt
[root@centos6 test2]
[root@centos6 test2]
*
[root@centos6 test2]
[root@centos6 test2]
[root@centos6 test2]
a aa b bb.txt cc.sh dd.txt ee.txt fff.txt k.txt
[root@centos6 test2]
[root@centos6 test2]
[root@centos6 test2]
a b
[root@centos6 test2]
[root@centos6 test2]
[root@centos6 test2]
[root@centos6 test2]
[root@centos6 test2]
总用量 4
-rw-r--r--. 1 root root 0 11月 25 17:26 a
-rw-r--r--. 1 root root 0 11月 25 17:02 aa
-rw-r--r--. 1 root root 0 11月 25 17:26 a b
-rw-r--r--. 1 root root 0 11月 25 17:26 b