Remove all files except some from a directory

前端 未结 19 1153
生来不讨喜
生来不讨喜 2020-11-30 16:36

When using sudo rm -r, how can I delete all files, with the exception of the following:

textfile.txt
backup.tar.gz
script.php
database.sql
info.         


        
19条回答
  •  日久生厌
    2020-11-30 16:41

    This is similar to the comment from @siwei-shen but you need the -o flag to do multiple patterns. The -o flag stands for 'or'

    find . -type f -not -name '*ignore1' -o -not -name '*ignore2' | xargs rm

提交回复
热议问题