Find files containing a given string

If you want to find files containing a specificly given string and you want to remove those files, you should simply use this oneliner (Only searching for files in the current directory):

 

find . | xargs grep -l "STRING_TO_SEARCH_FOR" | awk '{print "rm -f "$1}' > remove.sh && chmod u+x remove.sh

After that, you only have to execute the script and the files containing the searched string will be removed. Attention: You should take a look at remove.sh before executing it, just avoiding that files will be removed accidentally.

./remove.sh

Das könnte Dich auch interessieren …

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Time limit is exhausted. Please reload the CAPTCHA.