文件通配符與命令行擴展

* 匹配零個或多個字符
? 匹配任何單個字符
~ 當前用戶家目錄
~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:]?? 控制(非打?。┳址?/div>
[: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

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/88301

(0)
金色之謎金色之謎
上一篇 2017-11-11 18:13
下一篇 2017-11-12 13:10

相關推薦

  • rsyslog配置詳解,結合mysql+loganalyzer展現

        環境:Centos7.2 前言:系統日日夜夜不停地運行著,有這么一個守護進程,兢兢業業地不斷記錄它運行產生的日志,有不起眼的閑言碎語,值得管理員撇一眼的系統報錯,也默默地接收來自進程的嚴厲警告,甚至在內核崩潰前夕,同樣不遺余力記錄著當時發生的情形。他是無言的記錄者,沒有特別的修辭,但他的記錄的文字卻擲地有聲。本…

    系統運維 2016-10-25
  • N22-第一周(作業)

    馬哥教育網絡班22期-第一周課程練習:   一.描述計算機的組成及其功能       計算機組成:CPU :包含控制器,運算器,寄存器,緩存。通過時序復用的方式來處理加工來自輸入設備的指令或數據,協調各組件之間的工作       存儲器(內存):編址存儲單元陣列,用于暫時存放CP…

    Linux干貨 2016-08-13
  • 一個簡單的負載均衡集群:web服務

    一個簡單的負載均衡集群:以web服務為例 實驗環境:三臺主機(CentOS 7.3)             主機1:IP地址 172.18.0.88(Haproxy代理服務器)             主機2:IP地址 172.…

    Linux干貨 2017-05-17
  • Nginx淺談(一)

    淺談nginx(一) 此文主要介紹nginx的基礎知識及其基本配置,一為鞏固,二為記錄 知識點: nginx的作用 nginx的基本配置框架 nginx一些常用模塊介紹 1、什么是nginx     nginx是一款免費的,開源的,高性能的HTTP服務軟件,它不僅能     夠支…

    Linux干貨 2017-01-15
  • 三次握手和四次揮手

    今天來聊一下事實標準協議TCP/IP中傳輸層里TCP協議中,主機與服務器建立連接時的三次握手,和斷開連接時的四次揮手。 本博文分兩部分介紹,    一:狀態詳解    二:三次握手和四次揮手狀態介紹 這里總共涉及到十種狀態,其實總共有十一種狀態,接下來分別介紹一下它們; 一:狀態詳解 CLOSED:關閉—&…

    2017-09-01
  • 圖解Man

    個人淺見 歡迎指正

    Linux干貨 2016-10-18
欧美性久久久久