linux文件名通配符:* ? [:digit:]数字 [:lower:]小写字母 [:upper:]大写字母
? ?通配符命令簡介:
? ? ? 匹配符合相關條件的符號,匹配文件名查找。
? 通配符類型:
? ? ? *:匹配任意長度的任意字符
? ? ? ??:匹配任意單個字符
? ? ? ?[]:匹配指定范圍內的任意單個字符
? ? ? ?[^]:匹配指定范圍之外的任意單個字符
? ? ? ?[:space:]:空白字符
? ? ? ?[:punct:]:標點符號
? ? ? ?[:lower:]:小寫字母
? ? ? ?[:upper:]:大寫字母
? ? ? ?[:alpha:]:大小寫字母
? ? ? ?[:digit:]:數字
? ? ? ?[:alnum:]:數字和大小寫字母
? ?
通配符命令實例練習:
? 1、創建a123,cd6,c78m,cl my,m.z,k 67,8yu,789等文件:注意,以上是以逗號為分隔符,
? 其余都是文件名組成部分。
?[root@xuelinux test1]# touch a123 cd6 c78m 'cl my' m.z 'k 67'?8yu?789
? [root@xuelinux test1]# ls -l
總用量 0
-rw-r--r--. 1 root root 0 10月 11 14:34 789
-rw-r--r--. 1 root root 0 10月 11 14:34 8yu
-rw-r--r--. 1 root root 0 10月 11 14:34 a123
-rw-r--r--. 1 root root 0 10月 11 14:34 c78m
-rw-r--r--. 1 root root 0 10月 11 14:34 cd6
-rw-r--r--. 1 root root 0 10月 11 14:34 cl my
-rw-r--r--. 1 root root 0 10月 11 14:34 k 67
-rw-r--r--. 1 root root 0 10月 11 14:34 m.z
? 2、顯示所有以a或者m開頭的文件:?
? ? ls -l [am]*
[root@xuelinux test1]# ls -l [am]*
-rw-r--r--. 1 root root 0 10月 11 14:34 a123
-rw-r--r--. 1 root root 0 10月 11 14:34 m.z
?3、顯示所有文件名中包含了數字的文件:
? ? ls -l *[0-9]* 或者ls -l *[[:digit:]]*
[root@xuelinux test1]# ls -l *[0-9]*
-rw-r--r--. 1 root root 0 10月 11 14:34 789
-rw-r--r--. 1 root root 0 10月 11 14:34 8yu
-rw-r--r--. 1 root root 0 10月 11 14:34 a123
-rw-r--r--. 1 root root 0 10月 11 14:34 c78m
-rw-r--r--. 1 root root 0 10月 11 14:34 cd6
-rw-r--r--. 1 root root 0 10月 11 14:34 k 67
? 4、顯示所有以數字結尾且文件名中不包含空白符的文件:
? ? ?ls -l *[^[:space:]]*[0-9] ?此命令無法精確排除,所以通配符不能完美的匹配此類情況。
[root@xuelinux test1]# ls -l *[^[:space:]]*[0-9]
-rw-r--r--. 1 root root 0 10月 11 14:34 789
-rw-r--r--. 1 root root 0 10月 11 14:34 a123
-rw-r--r--. 1 root root 0 10月 11 14:34 cd6
-rw-r--r--. 1 root root 0 10月 11 14:34 k 67 ? 此文件名按道理是不應該被匹配的
? 5、顯示文件名中包含了非字母或數字的特殊符號的文件:
? ? ls -l *[^[:alnum:]]*
[root@xuelinux test1]# ls -l *[^[:alnum:]]*
-rw-r--r--. 1 root root 0 10月 11 14:34 cl my
-rw-r--r--. 1 root root 0 10月 11 14:34 k 67
-rw-r--r--. 1 root root 0 10月 11 14:34 m.z
轉載于:https://blog.51cto.com/woyaoxuelinux/1860662
總結
以上是生活随笔為你收集整理的linux文件名通配符:* ? [:digit:]数字 [:lower:]小写字母 [:upper:]大写字母的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 连接 insance 到 vlan101
- 下一篇: 通过重建Hosting系统理解HTTP请