8

I have about 1k+ mails in an inbox (old cronjob stdout). How do I 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 no 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.

15

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 *.

2

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
  • 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 'SO- stop being evil' Aug 12 '12 at 20:55
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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