delete all files with certain text
I have a mailserver and it archives all emails sent and received. The problem is it is also archiving all the spam messages that the postmaster account grabs (which are the ones that score so high they are getting rejected).
The archive directory structure looks like this: /etc/mail/archive/2008-04-21/ and then under there are all the messages. What I want to do is from the archive dir, basically say 'delete anything in all the directories under here where this string is found in the file: X-Spam-Status: Yes'. Note that space after the colon after the word Status..that might make the grep problematic... Any ideas? |
That's not a problem. It can be a problem if there are blank spaces in file names, but you can circumvent it by
Code:
grep -lZ "X-Spam-Status: Yes" /etc/mail/archive/*/* | xargs -0 echo rm |
ls -1 /etc/mail/archive/2008-04-21/ | while read file
do grep -q "X-Spam-Status: Yes" $file && rm $file done |
Thanks!
Either one of those worked perfectly!! Thank you thank you!!! |
All times are GMT -5. The time now is 02:38 PM. |