LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-21-2008, 09:09 AM   #1
dougp23
Member
 
Registered: Oct 2006
Posts: 43

Rep: Reputation: 15
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?

Last edited by dougp23; 04-21-2008 at 09:10 AM.
 
Old 04-21-2008, 09:27 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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
the -l option to grep prints only file names with matches. The -Z option separates file names with a NULL character and the -0 option to xargs takes input with fields separated by NULL. In the statement above I put an "echo rm" command to test the result. When you've checked you can strip out the echo command and the files will be actually removed.
 
Old 04-21-2008, 09:28 AM   #3
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
ls -1 /etc/mail/archive/2008-04-21/ | while read file
do
grep -q "X-Spam-Status: Yes" $file && rm $file
done
 
Old 04-21-2008, 01:17 PM   #4
dougp23
Member
 
Registered: Oct 2006
Posts: 43

Original Poster
Rep: Reputation: 15
Thanks!

Either one of those worked perfectly!!

Thank you thank you!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What are these files and can I delete them? upwordz Linux - Newbie 4 05-23-2007 08:14 AM
How to delete postmaster mails lenson Linux - Software 1 10-17-2006 01:48 AM
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 09:14 PM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 01:13 PM
Can't delete some files... Tomcat_cdm Linux - Newbie 2 03-11-2003 10:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration