on-internet
← Community

Bash - how to find and remove all files that contain a given string?

Stack Overflow ·

Let's say there's a number of files in a given directory with various file extensions or no extensions at all. Some of these files include the string "\/for\/endetta". How do I find and remove all the files in that directory matching this pattern? I could sort of do this by using: find -type f -exec egrep -Il '\/for\/endetta' {} \;|xargs rm -fv But is it possible to do it without xargs? And how do I properly escape the \s and /s, etc.

Comments

Sign in or sign up to comment and upvote.

No comments yet.