linux下的通配符与特殊符号

在bash的操作环境中海油一个非常有用的功能,那就是通配符(wildcard)。我们呢利用bash处理出具就更加方便了。下面我们列出一些常用的通配符,

符号意义
*代表0个到无穷多个任意字符
代表一定有一个任意字符
[]同样代表一定有一个在中括号内的字符(非任意字符)。例如[abcd]代表有一个字符,可能是a,b,c,d这四个的任何一个
[-]若有减号在括号内时,代表在编码顺序内的所有字符,例如[0-9]代表0到9之间的所有数字,因为数字的语系编码是连续的
[^]若中括号内的第一个字符为指数符号(^),那表示原向选择,例如[^abc]代表一个有一个字符,只要是非a,b,c的其他字符就接收的意思
接下来看一个例子:

root@tian-desktop:~# ll -d /etc/cron*
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/cron.d/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/cron.daily/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/cron.hourly/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/cron.monthly/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/cron.weekly/
-rw-r--r-- 1 root root  724 Apr 15  2010 /etc/crontab

root@tian-desktop:~# ll -d /etc/?????
drwxr-xr-x 3 root root 4096 Apr 29  2010 /etc/avahi/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/byobu/
drwxr-xr-x 4 root root 4096 Apr 29  2010 /etc/dhcp3/
drwxr-xr-x 3 root root 4096 Jun  2  2014 /etc/emacs/
drwxr-xr-x 4 root root 4096 Apr 29  2010 /etc/fonts/
-rw-r--r-- 1 root root  756 Jun  2  2014 /etc/fstab
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/gamin/
drwxr-xr-x 6 root root 4096 Apr 29  2010 /etc/gconf/
drwxr-xr-x 3 root root 4096 Apr 29  2010 /etc/gnome/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/gre.d/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/groff/
-rw-r--r-- 1 root root  868 May 18  2014 /etc/group
-rw-r--r-- 1 root root  258 May 12  2014 /etc/hosts
-rw-r--r-- 1 root root   24 Apr 23  2010 /etc/issue
-rw-r--r-- 1 root root  267 Apr 23  2010 /etc/legal
-rw-r--r-- 1 root root  111 Apr  1  2010 /etc/magic
drwxr-xr-x 3 root root 4096 Oct 27 14:14 /etc/mysql/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/pam.d/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/pango/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/pulse/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rc0.d/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rc1.d/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rc2.d/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rc3.d/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rc4.d/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rc5.d/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rc6.d/
drwxr-xr-x 2 root root 4096 Jun  2  2014 /etc/rcS.d/
drwxr-xr-x 2 root root 4096 Apr 29  2010 /etc/samba/
drwxr-xr-x 3 root root 4096 Apr 29  2010 /etc/sound/

root@tian-desktop:~# ll -d /etc/*[0-9]*
drwxr-xr-x 10 root root 4096 Apr 29  2010 /etc/X11/
drwxr-xr-x  5 root root 4096 Apr 29  2010 /etc/dbus-1/
drwxr-xr-x  4 root root 4096 Apr 29  2010 /etc/dhcp3/
drwxr-xr-x  3 root root 4096 Apr 29  2010 /etc/firefox-3.0/
drwxr-xr-x  3 root root 4096 Apr 29  2010 /etc/gnome-vfs-2.0/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/gtk-2.0/
drwxr-xr-x  2 root root 4096 Apr 29  2010 /etc/iproute2/
-rw-r--r--  1 root root  801 Apr 19  2010 /etc/mke2fs.conf
-rw-r--r--  1 root root 7649 Apr 29  2010 /etc/pnm2ppa.conf
drwxr-xr-x  5 root root 4096 Apr 29  2010 /etc/polkit-1/
drwxr-xr-x  2 root root 4096 Apr 29  2010 /etc/python2.6/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/rc0.d/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/rc1.d/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/rc2.d/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/rc3.d/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/rc4.d/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/rc5.d/
drwxr-xr-x  2 root root 4096 Jun  2  2014 /etc/rc6.d/
-rw-r--r--  1 root root 8596 Feb 16  2010 /etc/sensors3.conf
drwxr-xr-x  2 root root 4096 Apr 29  2010 /etc/w3m/
drwxr-xr-x  2 root root 4096 Apr 29  2010 /etc/xulrunner-1.9.2/

root@tian-desktop:~# ll -d /etc/[^a-z]*
drwxr-xr-x  5 root root 4096 Apr 29  2010 /etc/ConsoleKit/
drwxr-xr-x  5 root root 4096 Apr 29  2010 /etc/NetworkManager/
drwxr-xr-x 10 root root 4096 Apr 29  2010 /etc/X11/
除了通配符之外,bash环境中的特殊字符有还有:

#批注符号,这个最常被用在script当中,视为说明,其后的数据均不执行
\转义符号,将“特殊字符或通配符”还原成一般字符
|管道(pipe),分隔两个管道命令的界定
;连续命令执行分隔符,连续性命令的界定
~用户的主文件夹
$使用变量前导符,即是变量之前需要加的变量替换
!逻辑运算意义上的“非”的意思
&作业控制,将命令变成背景下作业
/目录符号,路径分隔的符号
>数据流重定向,输出导向,“替换”
<数据流重定向,输入导向
' '单引号,不具有变量置换的功能
""双引号,具有变量置换的功能
``两个"`"中间为可以先执行的命令,也可使用$()代替
()在中间为子shell的起始于结束
{}在中间为命令块的组合
  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值