本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/88301
* 匹配零個或多個字符
? 匹配任何單個字符
~ 當前用戶家目錄
~mage 用戶mage家目錄
~+ 當前工作目錄
~- 前一個工作目錄
[0-9] 匹配數字范圍
[a-z] 字母
[A-Z]字母
???????? [a-Z] 會以aAbBcC…小大小大列出,特別要注意
[wang] 匹配列表中的任何的一個字符
[^wang]匹配列表中的所有字符以外的字符
其他特殊字符
\ ? 轉義,跳脫符號:將『特殊字符或通配符』還原成一般字符
| 管道 (pipe):分個兩個管道命令的界定;
; ?? 連續指令下達分隔符: (注意!與管道命令不相同)
& ? ? ? 工作控制 (job control):將指令變成成背景下工作
! 邏輯運算意義上的『非』 not 癿意思
預定義的字符類:man 7 glob
[:digit:]? 任意數字,相當于0-9
[:lower:]?? 任意小寫字母
[:upper:]?? 任意大寫字母
[:alpha:] ? 任意大小寫字母
[:alnum:]?? 任意數字或字母
[:blank:]? 水平空白字符
[:space:]? 水平或垂直空白字符
[:punct:]? 標點符號
[:print:]? 可打印字符
[:cntrl:]?? 控制(非打印)字符
[:graph:]? 圖形字符
[:xdigit:]? 十六進制字符
1、顯示/test目錄下所有以l開頭,以一個小寫字母結尾,且中間出現至少一位數字的文件或目錄
方法1
#ls -d /test/l*[0-9]*[[:lower:]]
/test/ll4898ufjAj /test/ll4ufjAAj /test/ll4ufjAj /test/ll4ufjAjc
方法2
#ls -d /test/l*[[:digit:]]*[[:lower:]]
/test/ll4898ufjAj /test/ll4ufjAAj /test/ll4ufjAj /test/ll4ufjAjc
方法3
#ls -d /test/l*[^a-zA-z]*[[:lower:]]
/test/ll4898ufjAj /test/ll4ufjAAj /test/ll4ufjAj /test/ll4ufjAjc
2、顯示/test目錄下以任意一位數字開頭,且以非數字結尾的文件或目錄
方法1
#ls -d /test/[[:digit:]]*[[:alpha:]]
/test/112prueiruenjfdkeIEJI88.conf
方法2
#ls -d /test/[0-9]*[^0-9]
/test/112prueiruenjfdkeIEJI88.conf
方法3
#ls -d /test/[[:digit:]]*[a-zA-Z]
/test/112prueiruenjfdkeIEJI88.conf
3、顯示/test/目錄下以非字母開頭,后面跟了一個字母及其它任意長度任意字符的文件或目錄
方法1
#ls -d /test/[0-9][[:alpha:]]*
/test/0ll4ufjAjBB007
方法2
#ls -d /test/[^[:alpha:]][[:alpha:]]*
/test/0ll4ufjAjBB007
方法3
#ls -d /test/[^a-zA-Z][a-zA-Z]*
/test/0ll4ufjAjBB007
4、顯示/test/目錄下所有以rc開頭,并后面是0-6之間的數字,其它為任意字符的文件或目錄
#ls -d /test/rc[0-6]*
/test/rc1rjeirie /test/rc2jidf9fdjfd /test/rc556kkfjdjfkd
5、顯示/etc目錄下,所有以.d結尾的文件或目錄
#ls -d /etc/*.d
/etc/bash_completion.d /etc/logrotate.d /etc/rc1.d /etc/rwtab.d
/etc/chkconfig.d /etc/lsb-release.d /etc/rc2.d /etc/sane.d
/etc/cron.d /etc/makedev.d /etc/rc3.d /etc/setuptool.d
/etc/depmod.d /etc/modprobe.d /etc/rc4.d /etc/statetab.d
6、顯示/test目錄下,所有.conf結尾,且以m,n,r,p開頭的文件或目錄
#ls -d /test/[mnrp]*.conf
/test/mrueiruenjfdkeIEJI88.conf /test/prueiruenjfdkeIEJI88.conf
/test/nrueiruenjfdkeIEJI88.conf /test/rrueiruenjfdkeIEJI88.conf
7、只顯示/root下的隱藏文件和目錄
#ls -d /root/.[^.]*
/root/.abrt /root/.cshrc /root/.gtk-bookmarks /root/.nautilus
/root/.bash_history /root/.dbus /root/.gvfs /root/.pulse
/root/.bash_logout /root/.esd_auth /root/.history /root/.pulse-cookie
/root/.bash_profile /root/.gconf /root/.ICEauthority /root/.ssh
8、只顯示/root下的隱藏目錄
#ls -d /root/.[^.]*/
/root/.abrt/ /root/.dbus/ /root/.gnote/ /root/.local/ /root/.ssh/
/root/.cache/ /root/.gconf/ /root/.gnupg/ /root/.nautilus/
/root/.config/ /root/.gnome2/ /root/.gvfs/ /root/.pulse/
9、只顯示/etc下的非隱藏目錄
#ls -d /etc/[^.]*/
/etc/abrt/ /etc/gcrypt/ /etc/ntp/ /etc/reader.conf.d/
/etc/acpi/ /etc/gdm/ /etc/obex-data-server/ /etc/redhat-lsb/
括號擴展: { }
重復字符串的簡化形式
分號分隔具體內容
#touch file{1,3,5};ls file*
file1 file3 file5
{起始值..結束值}
#echo {0..10}
0 1 2 3 4 5 6 7 8 9 10
#echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
#echo {A..Z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
#echo {a..Z}
a ` _ ^ ] [ Z
{格式..最大值..步進數}
#echo {000..10..1}
000 001 002 003 004 005 006 007 008 009 010
贊 (0)
面向對象的實例方法,類方法和靜態方法
上一篇
2017-11-11
第十二周作業
下一篇
2017-11-12