linux下的通配符和特殊符号

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}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值