Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 8 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


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.