167

I set up a cronjob a long time ago that now doesn't exist. Whenever I open up Terminal, it now says "You have mail". I have something like 100 messages that all say the same thing. How do I mass delete all of the messages?

3
  • 1
    I wasn't even aware an MTA was built into OS X. Though now that I think about it, frankly I'm not surprised. Oct 21, 2011 at 22:48
  • @JasonSalaz I forgot to ask you, what's an MTA?
    – daviesgeek
    Feb 1, 2012 at 2:47
  • 1
    Mail Transfer Agent. When in doubt, Wikipedia. I know of, at least, MTAs, MSAs, MDAs, and MUAs. Feb 1, 2012 at 4:27

4 Answers 4

324

Launch the UNIX mail utility by running the following at the command prompt (in e.g. Terminal.app):

$ mail

You'll see a list of all your messages. From the mail prompt, do

? delete *
? q

And that should be it. Make sure to enter q after the delete * command. This will save the changes to disk.

6
  • At first I didn't know what mail app mean. To anyone who is having same trouble, "It is a command". Just go type it in terminal and you will get an interactive app running there. +1 Thank you
    – Nabin
    Mar 18, 2017 at 12:15
  • 1
    You can use del 1 where 1 is the message number too in case you need to keep some email for debugging purposes.
    – Fadli Saad
    Jan 27, 2019 at 7:31
  • kept following other answers but used exit to quit and would not work. Thanks for mentioning the q option.
    – frezq
    Aug 24, 2019 at 1:21
  • 3
    Anyone else visit this answer monthly?
    – Tom
    Oct 14, 2020 at 19:09
  • d * also works
    – dcsan
    Jul 3 at 18:56
18

You may also go the direct route and just run : > /var/mail/$USER to empty the mail file.

PS: Deleting the mail file requires sudo, just setting it to empty is enough.

0
5

I want to reinforce clearly one point how command [delete *],[q] really helped me out in this case.

I set a cron job to run like every day in 2018 (if I recall correctly) and forgot about it.

Now I realized to check and I discovered 3000 messages in my mailbox! Note to others that a quick edit can pile up reports rapidly.

0
4

I know this post is old, but I want to contribute with an answer.

to delete your mail messages do the following:

sudo rm /var/mail/[user]

And in order to the question, I suggest you do the following to each crontab you do not want to send an email notification (this way your mail will not have mails)

* * * * * /path/to/script.sh > /dev/null 2>&1

or

* * * * * command > /dev/null 2>&1
1
  • 1
    Notice that you should probably not drop stderr (FD 2). You usually want to be notified about errors so this is something which should be accessible. Aug 27, 2020 at 8:56

You must log in to answer this question.

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