Safely get rid of "You have new mail in /var/mail" on a Mac?
Solution 1
The old school way is to open a terminal and use
mail
at the prompt, then
d
to delete one message or
d1-4
for for four messages.
Then
q
to quit.
If you don't want to delete them unread, just type Enter at the mail prompt and it'll show each message in turn.
Use
man mail
for all the details.
Of course, other more sophisticated mail clients may be available, but that will do it.
Solution 2
In your ~/.bashrc
add:
unset MAILCHECK
Solution 3
You can just remove the messages from /var/mail/<user>
, but you might get more, for example as the result of cron jobs. You can instead have this mail redirected to the normal place you read and store mail on your machine with a .forward
file. Simply create a file called .forward
in /Users/<username>/
which contains the filename you wish the mail to be stored in.
e.g. in my case, I pull my mail down from my host using IMAP and store it in /Users/ether/mail/i
, so I have a file called /Users/ether/.forward
which contains the line: /Users/ether/mail/i
Related videos on Youtube
quack quixote
Updated on September 17, 2022Comments
-
quack quixote over 1 year
I was messing around with sendmail in Rails a year ago and have had this message popping up in the terminal after every command ever since:
You have new mail in /var/mail/Lance
How do I properly get rid of that so the message goes away? I ever use any of that functionality and don't have mail on my computer. There's one file in
/var/mail
calledlance
, and it's huge. Can I just remove it?-
Nikolai N Fetissov almost 14 yearsTake a look into the file - it holds mail undelivered to the user - and just remove it if you don't find anything useful there.
-
-
Nikolai N Fetissov almost 14 yearsOr
d *
for all messages. -
mattbornski almost 14 yearshow do I make it so it doesn't say "You have new mail" every time I execute a command in the terminal?
-
joaquin almost 14 yearsI checked - I had 210 messages waiting, the latest from January 2006, which is before I bought this computer! The data transfer service was thorough. I used
d 1-210
quite successfully. I didn't have anything reminding me, though. -
mattbornski almost 14 yearsit says I have 34,000 messages! I have 14,000 in gmail (don't delete all of them because I get 100+ per day, mostly group digests and production app notifications), and some coming from years ago. Thing is, before I messed with 'sendmail', I never got that "you've got mail" message. Now I do. I just want it to go away, can it? Some setting to disable the mail/terminal combo. Don't want to spend the time to sort/delete them.
-
longda over 11 yearsmake sure you type "q" or you deletions will not be saved (i was typing "x" like a moron for 10 mins)
-
line-o over 10 yearsthat won't help in getting rid of the file
-
user72923 almost 10 years@geotheory The choice between
.bashrc
and.bash_profile
is not specific to the version of the OS. Rather, it concerns login vs non-login shells. See here for more details: joshstaiger.org/archives/2005/07/bash_profile_vs.html -
abathur over 6 yearsThis under-rated answer led me to a good fix for my underlying question, which was how to keep the notification from appearing on macos, because I already know I've got mail. I tried MAILCHECK and other options to no avail, but redirecting the mail to a different file killed these nudges, but still lets me occasionally review cron mail to make sure all is well.
-
Nick over 5 yearsFor the fish shell, add
set --erase MAILCHECK
in~/.config/fish/config.fish
. -
1.61803 over 5 yearsUnsetting
MAILCHECK
doesn't seem to work on bash 4.4.12. Any ideas? -
Dennis Williamson over 5 years@1.61803: I just tested it in Bash 4.4.12 and it works for me.
-
1.61803 over 5 yearsAs per
bash
man page, I triedunset MAILCHECK
andexport MAILCHECK=-1
, no dice. -
Dennis Williamson over 5 years@1.61803: So after that you were still getting "You have new mail" messages in the same terminal that you entered that command?
-
1.61803 over 5 yearsI tested again and it seems to completely stop checking for
mail
(cron
messages in my case), whereas I only wanted to suppress the message in the shell. -
Dennis Williamson over 5 years@1.61803: What do you expect a check for mail performed by Bash to do except for notifying you via a message in the shell? Bash doesn't process the mail in any way. In fact the file it checks doesn't even really have to be mail. It just checks for a file to have changed.
-
1.61803 over 5 yearsI mean, since I unset it,
cron
jobs don't show anymore inmail
, it's empty. -
Dennis Williamson over 5 years@1.61803 Something else is causing that. You'll need to investigate what. And maybe ask a new question here or on unix.se.