remove files when name does NOT contain some words

后端 未结 3 1193
生来不讨喜
生来不讨喜 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:46

    This command should do what you you need:

    ls -1 | grep -v 'good' | xargs rm -f
    

    It will probably run faster than other commands, since it does not involve the use of a regex (which is slow, and unnecessary for such a simple operation).

提交回复
热议问题