Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
find and delete files containing
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
carpman
Advocate
Advocate


Joined: 20 Jun 2002
Posts: 2202
Location: London - UK

PostPosted: Thu Jul 05, 2007 3:44 pm    Post subject: find and delete files containing Reply with quote

Hello, have a mail server with 12000 emails in postfix que, most a bounces from 'mailer-deamon' webmin is to slow and dies if trying to delete to many so though i use console to search que and delete all email from mailer-deamon, problem is not sure to do this?


I know i can use following to find what email contain text string 'mailer-deamon but not how to combined this with delete?

to find text in file i would use

Code:

find /path -type f -print0 | xargs -r0 grep -F 'string'


any ideas

many thanks
_________________
Work Station - 64bit
Gigabyte GA X48-DQ6 Core2duo E8400
8GB GSkill DDR2-1066
SATA Areca 1210 Raid
BFG OC2 8800 GTS 640mb
--------------------------------
Notebook
Samsung Q45 7100 4gb
Back to top
View user's profile Send private message
blubbi
Guru
Guru


Joined: 27 Apr 2003
Posts: 564
Location: Halle (Saale), Germany

PostPosted: Thu Jul 05, 2007 4:07 pm    Post subject: Reply with quote

Try:

Code:
for i in $(grep -R -l PATTERN /PATH/*) ; do rm -i -- "$i" ; done


or even shorter:

Code:
rm -i $(grep -R -l PATTERN /PATH/*)



regards
blubbi


Last edited by blubbi on Thu Jul 05, 2007 4:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
carpman
Advocate
Advocate


Joined: 20 Jun 2002
Posts: 2202
Location: London - UK

PostPosted: Thu Jul 05, 2007 4:25 pm    Post subject: Reply with quote

blubbi wrote:
Try:

Code:
for i in $(grep -R -l PATTERN /PATH/*) ; do rm -i -- "$i" ; done


regards
blubbi



Thanks for reply, so could do

Code:

for i in $(grep -R -l mailer-deamon /var/spool/postfix/active/*) ; do rm -i -- "$i" ; done


Anyway of doing a pretend, just in case it delete mail i que i don't want deleted?

cheers
_________________
Work Station - 64bit
Gigabyte GA X48-DQ6 Core2duo E8400
8GB GSkill DDR2-1066
SATA Areca 1210 Raid
BFG OC2 8800 GTS 640mb
--------------------------------
Notebook
Samsung Q45 7100 4gb
Back to top
View user's profile Send private message
blubbi
Guru
Guru


Joined: 27 Apr 2003
Posts: 564
Location: Halle (Saale), Germany

PostPosted: Thu Jul 05, 2007 4:26 pm    Post subject: Reply with quote

or even shorter:

Code:
rm -i -- $(grep -R -l PATTERN /PATH/*)
Back to top
View user's profile Send private message
jlh
Tux's lil' helper
Tux's lil' helper


Joined: 06 May 2007
Posts: 145
Location: Switzerland::Zürich

PostPosted: Thu Jul 05, 2007 11:30 pm    Post subject: Reply with quote

Is there a max number of arguments that can be given to programs? If you have that many mails then you might hit it. If the commands above yield too many matches, try to use xarg to delete them, something like
Code:
grep -R -l PATTERN /PATH/* | xargs -rL 100 rm -i
This will run 'rm' repeatedly with each at most 100 arguments.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21724

PostPosted: Sat Jul 07, 2007 5:31 pm    Post subject: Reply with quote

jlh wrote:
Is there a max number of arguments that can be given to programs? If you have that many mails then you might hit it. If the commands above yield too many matches, try to use xarg to delete them, something like
Code:
grep -R -l PATTERN /PATH/* | xargs -rL 100 rm -i
This will run 'rm' repeatedly with each at most 100 arguments.


Yes, there is a maximum limit. GNU xargs can show the limit if you run xargs --show-limits. xargs is designed to compensate for this limit, so the only reason to restrict the number of arguments passed to the child program is if the child program cannot handle arbitrarily many arguments. As far as I know, rm has no such limitation, so you could just do xargs rm -i for the last portion of the pipeline.
Back to top
View user's profile Send private message
jlh
Tux's lil' helper
Tux's lil' helper


Joined: 06 May 2007
Posts: 145
Location: Switzerland::Zürich

PostPosted: Sun Jul 08, 2007 3:53 pm    Post subject: Reply with quote

Ah very cool. I didn't realize that xargs does that automatically when you specify no limits. (Feeling stupid that this wasn't obvious to me, as it makes a lot of sense.)
Back to top
View user's profile Send private message
carpman
Advocate
Advocate


Joined: 20 Jun 2002
Posts: 2202
Location: London - UK

PostPosted: Mon Jul 30, 2007 10:33 am    Post subject: Reply with quote

posted new thread
_________________
Work Station - 64bit
Gigabyte GA X48-DQ6 Core2duo E8400
8GB GSkill DDR2-1066
SATA Areca 1210 Raid
BFG OC2 8800 GTS 640mb
--------------------------------
Notebook
Samsung Q45 7100 4gb
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum