Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have some 1k+ mails in an inbox (old cronjob stdout), how to delete them in bulk?

I'm on Solaris 8 and I have only mail available, no pine or mutt or similar "UI"-based client.

Inline help and man page only give "d #" to delete a specific mail. I've tried for example d 1 - 100 but not luck. And I don't feel like doing d 1000 times...

Any ideas how to clean up this inbox? I'd actually like to purge all mails older than x days.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

While mail may not be able to, and you don't have pine or mutt you probably do have mailx. And mailx can d 5-10 or d *.

share|improve this answer

If you want to execute a d 1 through d 100, you could generate that sequence of commands and pipe it directly to mail:

i=1; while [ $i -le 100 ]; do echo d $i; i=$(($i+1)); done | mail
share|improve this answer
    
I have no Solaris here to check. If you run d 1, does it renumber subsequent emails? If so, you need to either loop backwards or run d 1 100 times. –  Gilles Aug 12 '12 at 20:55

The following will help you to read the mails during 1 second, delete the mail and move on to the next one. If all mails have been deleted loop will stop.

Want some more time? Change sleep to 2 or more. Want it faster? Replace sleep 1 by a dummy command.

while (echo dq |mail) do sleep 1 ;done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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