Delete a list of files with find and grep

后端 未结 9 1669
一个人的身影
一个人的身影 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 09:07

    To view what you are going to delete first, since rm -fr is such a dangerous command:

    find /path/to/file/ | grep car | xargs ls -lh
    

    Then if the results are what you want, run the real command by removing the ls -lh, replacing it with rm -fr

    find /path/to/file/ | grep car | xargs rm -fr
    

提交回复
热议问题