Super User is a question and answer site for computer enthusiasts and power users. 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

How can I empty gmail inbox from bash or sh? Can it be done using gmail POP3 server or imap? I found a way to read emails via atom but it seems that it does not work via POP3 so the emails stay in the inbox.

share|improve this question
Please don't double-post: – ziesemer Jan 1 '12 at 5:40

Connect to Gmail IMAP using any console IMAP client:

  • mutt:

    mutt -f "imaps://"


  • alpine, re-alpine

    alpine -f "{}INBOX"
  • heirloom-mailx, GNU mailutils

    mail -f "imaps://"

    Delete all: d *q

  • Python:

    import imaplib
    im = imaplib.IMAP4_SSL("")
    im.login("user", "passwd")
    typ, data =, 'ALL')
    for num in data[0].split():, '+FLAGS', '\\Deleted')
share|improve this answer

you can use poplib module of python to check the mail and delete it accordingly see this for details

share|improve this answer

I guess you can do it quickly by logging in via the web. Click on the checkbox on the top of the list. This will select the first page mails. Now you will notice a link which will have a text which goes like "All xx conversations on this page are selected. Select all xxx conversations in Inbox" where xx is the number of conversations you see in the page and xxx is the number of total mails. Click on that link and then click on the bin icon (Delete). This will delete all your inbox. Follow the similar procedure for the outbox and drafts. Done!

share|improve this answer
While this accomplishes the end result, Nutel is interested in doing this through bash or the terminal. – iglvzx Jan 1 '12 at 5:58
@iglvzx Maybe this can be done in Lynx? – Daniel Beck Jan 1 '12 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .