Delete a list of files with find and grep

后端 未结 9 1824
一个人的身影
一个人的身影 2021-01-30 08:44

I want to delete all files which have names containing a specific word, e.g. \"car\". So far, I came up with this:

find|grep car

How do I pass

9条回答
  •  轮回少年
    2021-01-30 08:59

    A bit of necromancy, but you can also use find, grep, and xargs

    find . -type f | grep -e "pattern1" -e "pattern2" | xargs rm -rf
    

    ^ Find will need some attention to make it work for your needs potentially, such as is a file, mindepth, maxdepth and any globbing.

提交回复
热议问题