1、linux下的通配符和特殊符号
* 通配符,代表0个或多个字符或数字
? 通配符,代表一定有一个字符
& 将命令变为后台命令
$ 变量之前,要加的变量替换符
>,>> 输出导向,分别是“替换”和“累加”
! 逻辑意义上的非
[ ] 中间为字符的组合,只表示有一个字符
| 分隔两个命令的管道命令
{ } 中间为命令区块的组合
` 反引号,用于执行命令
通配符里面,最常用的就是, * , ? , [ ] , 以及 `
2、通配符的使用小例子
#显示所有以 .sh 结尾的文件
[root@localhost shellsh]# ls *.sh
10.sh 1.sh 2.sh 3.sh 4.sh 5.sh 6.sh 7.sh 8.sh 9.sh
#?问号表示,一个字符
#显示 1.后面有一个字符的文件
# ls 1.???
[root@localhost shellsh]# ls 1.?
1.c
#将 1.sh 2.sh 3.sh 4.sh 5.sh ,若存在的话,就复制到 /etc 目录下
[root@localhost shellsh]# cp [1-5].sh /etc
#检查有没有复制成功
[root@localhost etc]# ls | grep '\.sh$'
1.sh
2.sh
3.sh
4.sh
5.sh
# ! 相当于逻辑意义上的非
<pre name="code" class="sql">#将只要不是 1.sh 2.sh 3.sh 4.sh 5.sh 文件 ,若存在的话,就复制到 /etc 目录下
[root@localhost shellsh]# cp [!1-5].sh /etc
#检查有没有复制成功
[root@localhost etc]# ls | grep '\.sh$'
6.sh
7.sh
8.sh
9.sh
#关于` 反引号, 用于执行命令#删除以 .sh 结尾的文件[root@localhost etc]# ls | grep '\.sh$'
6.sh
7.sh
8.sh
9.sh
[root@localhost etc]# rm `ls | grep '\.sh$'`
rm: remove regular file `6.sh'? y
rm: remove regular file `7.sh'? y
rm: remove regular file `8.sh'? y
rm: remove regular file `9.sh'? y
[root@localhost etc]# ls | grep '\.sh$'
# & 后台运行一个命令# 当一个命令运行比较耗时的时候,可以让命令后台运行
[root@localhost etc]# ll &
#关于文件的重定向# > 替换, 没有的话会新建,文件;如果文件已经存在,会替换文件的内容# >> 追加, 会在文件的内容后面追加新的内容# > 文件不存在,会新建
[root@localhost test]# echo " hello world " > out.txt
[root@localhost test]# cat out.txt
hello world # > 替换文件的内容[root@localhost test]# echo "i am coming " > out.txt
[root@localhost test]# cat out.txt
i am coming # >> 累加,追加在文件的后面[root@localhost test]# echo " hello world " >> out.txt
[root@localhost test]# cat out.txt
i am coming
hello world
# { } 具有分组展开的功能# 可通过下面的命令创建多个文件夹mkdir -pv /mnt/test/x/m /mnt/test/y
mkdir -pv /mnt/test/{x/m,y}