15

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.

Anthony Geoghegan
  • 12,605
  • 7
  • 59
  • 62
GWu
  • 263
  • 1
  • 2
  • 7

3 Answers3

24

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

bahamat
  • 38,658
  • 4
  • 70
  • 103
3

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
Jim Paris
  • 14,137
  • 5
  • 36
  • 35
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
slm
  • 363,520
  • 117
  • 767
  • 871
Geert
  • 21
  • 1