remove files when name does NOT contain some words

后端 未结 3 1212
生来不讨喜
生来不讨喜 2020-12-30 10:54

I am using Linux and intend to remove some files using shell.

I have some files in my folder, some filenames contain the word \"good\", others don\'t. For example:

3条回答
  •  清歌不尽
    2020-12-30 11:38

    With bash, you can get "negative" matching via the extglob shell option:

    shopt -s extglob
    rm !(*good*)
    

提交回复
热议问题