Delete a list of files with find and grep

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

    You can use ls and grep to find your files and rm -rf to delete the files.

    rm -rf $(ls | grep car)
    

    But this is not a good idea to use this command if there is a chance of directories or files, you don't want to delete, having names with the character pattern you are specifying with grep.

提交回复
热议问题