[Nottingham] saved by the shell ?

Peter Chang Peter.Chang at nottingham.ac.uk
Tue May 20 18:44:39 BST 2008


Martin,

> i have shell access to the server so was hoping i could use some command-line
> trickery to remove all messages with a given subject line.
>
> after a bit of googling i figure i need something along the lines of :-
> 	grep "My Subject Line" ./* | xargs rm
> but i'm getting an error "bin/grep: Argument list too long"
>
> can anyone put me on the right track ?

The recipe you gave doesn't do what you want!

The error is just that there's too many files in your mail directory. So 
you need to use find(1) to generate a list of filenames then go through 
each to see if it contains the '^Subject: My subject' line and then delete 
accordingly.

$ find $mymaildir -type f -exec grep -q '^Subject: My subject' {} \; \
-print0 | xargs -0 rm -f

Best to check that is actually does what you need by replacing 'rm -f' 
with 'echo'.

hth,
  Peter



This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.




More information about the Nottingham mailing list