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

Due to some bad cron jobs I now have ~1600 mail messages, most of them containing the same error log. I would like to quickly group them by subject and delete them, while limiting the chances of missing some important message.

I couldn't figure out a way to do anything using the mail command other than deleting each message individually. I tried installing pine, but it seems that even there I have to go over each message individually and hit the D key.

Surely there's a way to script this. Right?

I'm using ubuntu server 10.04.

share|improve this question
up vote 4 down vote accepted

Mutt is really good at this. You could tag-pattern (shift-T) on the common subject string, then tag-prefix (;) delete (d) the matching messages.

"Mutt Manual, Using Tags"

share|improve this answer

If your mails are in a Maildir (like e.g. ~/Maildir/cur) you can just use grep and rm:

grep -l "Subject: My error log message" ~/Maildir/cur/* | xargs rm

if instead they are in a mbox this of course doesn't work.

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.