Shell 內建命令 shopt extglob 選項

來源:互聯網
上載者:User

標籤:

簡介

shopt 命令可以設定 shell 的選擇性參數.

shopt [-psu] [optname …]

-s 開啟某個選項.

-u 關閉某個選項.

-p 列出所有可設定的選項.

extglob選項

如果開啟 extglob 選項, shell 將啟用模式比對. 可參考 ■ Shell 模式比對

查看 extglob 選項是否開啟(預設是off)

$ shopt extglobextglob off

開啟 extglob 選項

$ shopt -s extglob

此時查看 extglob 選項是否開啟

$ shopt extglob   extglob on

關閉 extglob 選項

$ shopt -u extglob
執行個體

將目錄下所有的檔案和目錄移動到 backup 目錄中.

目前的目錄下3個檔案以及兩個目錄

$ lsdir1  dir2  file1  file2  file3

建立一個 backup 目錄

$ mkdir -p backup

將除了 backup 目錄的其他檔案和目錄移動到 backup 目錄下

$ mv !(backup) backup/

查看結果

$ lsbackup$ ls backup/dir1  dir2  file1  file2  file3

刪除目前的目錄下所有file開頭的檔案或目錄

$ lsbackup  dir1  dir2  file1  file2  file3$ rm -rf file[1-3]$ lsbackup  dir1  dir2

移動除了 dir1 目錄以及 file1 檔案到 backup 目錄下

$ mv !(dir1|file1|backup) backup/$ lsbackup  dir1  file1$ ls backup/dir2  file2  file3

其他的需求還需要結合 shell 模式比對進行舉一反三.

Shell 內建命令 shopt extglob 選項

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.