Deleting all e-mail messages in your inbox with mutt

Occasionally, I'll end up with a mailbox full of random data, alerts, or other useless things. If you have SSH access to the server, you can always clear out your mail spool, but if you connect to an IMAP server, you can use mutt to do the same thing.

First, use mutt to connect to your server remotely (via IMAP over SSL in this example):

mutt -f imaps://mail.yourdomain.com/

Once you've connected and logged in, press SHIFT-D (uppercase d). The status bar of mutt should show:

Delete messages matching:

Type in ~s .* so that the line looks like:

Delete messages matching: ~s .*

When you press enter, mutt will put a D next to all of the messages, which marks them for deletion. Press q to quit, and then y to confirm the deletion. After a brief moment, all of those messages will be deleted and mutt will exit.

Update: If you review Dmitri's comment below, there's an even faster way to remove all of the messages in a mailbox with mutt. Just hold shift while pressing D, ~ (tilde), and A to select everything:

D~A
Printed from: http://rackerhacker.com/2009/06/19/deleting-all-e-mail-messages-in-your-inbox-with-mutt/ .
© Major Hayden 2012.

7 Comments   »

  • Phil Dufault says:

    The easier way is:
    T~s .*;d$

    T to enable tag mode, ~s.* to select everything matching your subject (or .* for everything), and ;d to delete said tagged messages. The final $ will cause mutt to sync your changes to the mailbox if you don't want to quit.

  • Thanx for this great Tutorial!

  • Hendy Irawan says:

    Thanks a lot! I just did this with my 1600+ (junk) mutt messages. Really helpful.

  • ~s .* selects all messages by subjects. A better (IMHO) way to select all messages is:

    ~A

    It does not expect any regular expressions, it just selects everything. To mark all messages as deleted, press:

    D~A

  • Major Hayden says:

    Dmitri - that's a handy tip!

  • "D." - even shorter :)

  • Cj says:

    I always liked telnet its present on most systems as a client application so you don't need to install anything at all. Its great for killing over sized messages quickly that gum up regular email clients like outlook.

Trackbacks/Pingbacks

  1. Mutt Tips « High-Toned

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this