delete file that match the content
Greetings!
I have a dir with 10,000 text files and growing. Do you have a script where if the word "LINUXFORUMS" has on the body of the text file, it will automatically delete the file. I cannot get to it since I'm only familiar to BASH. Anyone have a script similar to this or any ideas how can i do this? Any links where it can direct me to this kind of script? TIA --linux newbie |
A very basic version to do this would be:
Code:
#!/bin/sh Have a look at the Advanced Bash Scripting Guide - it's well worth a read. |
You don't really need a script:
Code:
grep -l "LINUXFORUMS" /someDirectory/* | awk '{print "rm -f \""$0"\""}' | bash |
or
grep -l blah | xargs -n19 rm |
This is the one that fit the most but i will also the others. Thanks for all those who help
Quote:
|
If you are going to use xargs, you probably want:
Code:
grep -Z -l "LINUXFORUMS" /someDirectory/* | xargs -0 rm -f |
All times are GMT -5. The time now is 11:27 PM. |