Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

trying to figure out a cli way to empty all email from a specific email account.

It is certainly possible to type:

mutt -f account
D
~s .*
then quit....

Is there a way to do this all from cli/cron?

share|improve this question
1  
How is the mail stored? How are you accessing it? What type of mail storage is in use (mbox/maildir/other)? –  Zoredache Nov 22 '11 at 18:03
    
/var/spool/mail/ :) Local email accounts. No need for pop3/imap account stuff right now. –  CMag Nov 22 '11 at 18:06
1  
why do you want to do this? –  warren Nov 22 '11 at 20:33
add comment

closed as off topic by Zoredache, voretaq7 Oct 25 '12 at 19:37

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 4 down vote accepted

But echo -n > /var/spool/mail/account does the trick.

share|improve this answer
    
Make sure to do this as the user in question and not root or the file will end up with the wrong ownership. –  Ladadadada Nov 22 '11 at 19:55
    
exactly why it would be nicer to bang this out via mutt, no? :) hence the mutt question, not a trick with echo/touch/etc :) –  CMag Nov 22 '11 at 20:04
2  
(+1) So you'd rather have Mutt analyze every mail header and "re-render" an empty mailfile using billions of CPU and Disk cycles? Do the echo. It doesn't matter who you do it as if the file already exists the permissions will not be changed. Also, just for cleanliness lets do echo -n > /var/spool/mail/account so it doesn't start with a newline. –  Kyle Smith Nov 22 '11 at 20:30
    
You don't need the echo. >/var/spool/mail/account works and leaves a blank file rather than one with a linfeed in it. –  Iain Nov 22 '11 at 22:06
add comment

Would rm /var/spool/mail/account do the trick ?

share|improve this answer
    
dont know... that depends if postfix/dovecot wont complain about its absence, and recreate it! –  CMag Nov 22 '11 at 18:42
    
That was rhetorical. –  mailq Nov 22 '11 at 18:55
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.