linux檔案名稱通配

來源:互聯網
上載者:User

標籤:linux   檔案名稱萬用字元   萬用字元   

萬用字元是一種特殊語句,用來模糊搜尋檔案。當尋找檔案夾或目錄時,可以使用它來代替一個或多個真正字元

 

   萬用字元:
        *: 匹配任意長度的任一字元(包令0個字元)

        [[email protected] tt]# ls                ab  abb  abc  abm  xab  # 如有檔案        [[email protected] tt]# ls ab*            ab  abb  abc  abm    # 匹配以ab開頭後面跟著任一字元        [[email protected] tt]# ls *ab            ab  xab              # 匹配以ab結尾        [[email protected] tt]# ls *ab*            ab  abb  abc  abm  xab    #匹配包含ab的檔案

 

        ?:匹配任意單個字元

       [[email protected] tt]# ls a?            ab

        [ ]: 匹配指定字元範圍內的任意單個字元,萬用字元本身不會匹分大小寫這一點要注意到。

        [xyz]    # 匹配xyz        [a-z]    # 匹配a-z的字母集        [A-Z]   # 匹配大寫字母集        [0-9]   # 匹配數字        [0-9a-zA-Z]   # 匹配數字大小寫字母        [[email protected] tmp]# ls a[0-9]*        a1b  a2b  a3b  a4b  a5b  a6b  a7b  a8b  a9b

        建議使用POSI規範來匹配,如下的字元集可以匹分大小寫
        [[:upper:]]    所有大寫字母
        [[:lower:]]    小寫字母
        [[:alpha:]]    大小寫字母集
        [[:digit:]]      數字
        [[:alnum:]]   包含數字和字母表
        [[:space:]]    空格
        [[:punct:]]    標點符號


        [^]: 匹配指定字元範圍外的任意單個字元         對匹配的取反

  [[email protected] tmp]# rm -rf ./[^my]*   # 刪除目前的目錄中非my開頭的檔案,後面用了*號來表示後面不管是什麼結尾
  [^0-9]  # 非數字以外的任一字元  [^[:digit:]]  # 如果是字元集請用這種寫法

 

本文出自 “菜鳥日誌” 部落格,請務必保留此出處http://zkxfoo.blog.51cto.com/1605971/1660755

linux檔案名稱通配

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.