“You have new mail” message in Linux/UNIX


To totally unlock this section you need to Log-in


Login

A common scenario on most Linux systems is the following: "When I log into a box and 'su' to root, I get a cute little message saying I have mail.".

  • Where is this mail?
  • What does it contain?
  • Who/What sent it?
  • How important is it?

Is this even actual "mail" in the same sense as email? Or is it just my system telling me something?

Where is this mail?

It's likely to be in the spool file: /var/mail/$USER or /var/spool/mail/$USER are the most common locations on Linux and BSD.

"You have new mail" message in Linux/UNIX

Other locations are possible – check if $MAIL is set – but by default, the system only informs you about /var(/spool)/mail.

Usually the spool file is in a very simple mbox format, so you can open it in a text editor or pager.

For a slightly more convenient way, most distributions come with a program called mail (or Mail, mailx). You can try mutt or alpine; you can even configure it to be sent to an outside mailbox.

What does it contain? Who/What sent it?

Most often the messages contain output of cron jobs, or a system security report by logwatch, or similar junk. Read it and find out.

How important is it?

Depends greatly on the contents of each message.

You should at least scan the subject headers – often people ignore the mail for months never realizing that their daily cron jobs fail.

Is this even actual "mail" in the same sense as email? Or is it just my system telling me something?
Yes to both – it's generated by your system telling you something, but it's also actual email and can be handled as such.

You can (and should) configure your mail software – the "MTA" aka /usr/sbin/sendmail – to forward the messages to your personal mail address. The exact instructions vary depending on which MTA (if any) you have installed, whether this is a personal computer or a server, whether you have your own domain or use a @gmail.com, and so on.

Read your messages in Ubuntu

To see what messages you received from the command line, this command will reveal the message(s):

Show mails in /var/mail/root

cat /var/spool/mail/root

The message could look like this:

From root@hostname Wed Jul 29 12:05:26 2015
Return-Path: 
Received: from hostname (localhost [127.0.0.1])
by hostname (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id t6TG5QKu001540
for ; Wed, 29 Jul 2015 12:05:26 -0400
Received: (from root@localhost)
by hostname (8.14.4/8.14.4/Submit) id t6TG5QYK001533;
Wed, 29 Jul 2015 12:05:26 -0400
Date: Wed, 29 Jul 2015 12:05:26 -0400
Message-Id: <201507291605.t6TG5QYK001533@hostname>
To: root@hostname
From: root@hostname
Auto-Submitted: auto-generated
Subject: *** SECURITY information for hostname ***
 
hostname: Jul 29 12:05:26 : root : unable to resolve host hostname

Removing messages from /var/mail/root

To purge these messages and to get rid of the message you received on logging in, you can simply delete it with this command:

root@hostname:~# > /var/spool/mail/root

Do not forget to include the > sign, otherwise it won’t work.