View previous topic :: View next topic |
Author |
Message |
carpman Advocate
Joined: 20 Jun 2002 Posts: 2202 Location: London - UK
|
Posted: Thu Jul 05, 2007 3:44 pm Post subject: find and delete files containing |
|
|
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 |
|
|
blubbi Guru
Joined: 27 Apr 2003 Posts: 564 Location: Halle (Saale), Germany
|
Posted: Thu Jul 05, 2007 4:07 pm Post subject: |
|
|
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 |
|
|
carpman Advocate
Joined: 20 Jun 2002 Posts: 2202 Location: London - UK
|
Posted: Thu Jul 05, 2007 4:25 pm Post subject: |
|
|
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 |
|
|
blubbi Guru
Joined: 27 Apr 2003 Posts: 564 Location: Halle (Saale), Germany
|
Posted: Thu Jul 05, 2007 4:26 pm Post subject: |
|
|
or even shorter:
Code: | rm -i -- $(grep -R -l PATTERN /PATH/*) |
|
|
Back to top |
|
|
jlh Tux's lil' helper
Joined: 06 May 2007 Posts: 145 Location: Switzerland::Zürich
|
Posted: Thu Jul 05, 2007 11:30 pm Post subject: |
|
|
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 |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 21724
|
Posted: Sat Jul 07, 2007 5:31 pm Post subject: |
|
|
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 |
|
|
jlh Tux's lil' helper
Joined: 06 May 2007 Posts: 145 Location: Switzerland::Zürich
|
Posted: Sun Jul 08, 2007 3:53 pm Post subject: |
|
|
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 |
|
|
carpman Advocate
Joined: 20 Jun 2002 Posts: 2202 Location: London - UK
|
Posted: Mon Jul 30, 2007 10:33 am Post subject: |
|
|
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 |
|
|
|