When logging into your Ubuntu or Debian server, you might be greeted with the message You have new mail in /var/mail/root. But how do you read that mail and how did it get there?
It means that you have installed sendmail on Ubuntu (or any other flavour of Linux) and you received one or more messages in your inbox. The message(s) can originate from your system itself, or from an external e-mail address.
Read your messages in Ubuntu or Debian
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@sisrv.net Mon Oct 19 00:00:01 2020
Return-Path: <root@sisrv.net>
Received: from sisrv.net (localhost [127.0.0.1])
by sisrv.net (8.15.2/8.15.2/Debian-14~deb10u1) with ESMTP id 09J001q3000577
for <root@sisrv.net>; Mon, 19 Oct 2020 00:00:01 GMT
Received: (from root@localhost)
by sisrv.net (8.15.2/8.15.2/Submit) id 09J001dm000553
for root; Mon, 19 Oct 2020 00:00:01 GMT
Date: Mon, 19 Oct 2020 00:00:01 GMT
Message-Id: <202010190000.09J001dm000553@sisrv.net>
From: root@sisrv.net (Cron Daemon)
To: root@sisrv.net
Subject: Cron <root@4b4593bb> sudo tar -zcf /home/Backups/ircd_backup-$(date +%Y--%m-%d).tar.gz /home/ircd
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
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:
Purge messages from /var/mail/root
Simply type the following command at shell prompt to delete all root mail:
> /var/spool/mail/root
Do not forget to include the >
sign, otherwise it won’t work.
Verify it with the following command or cat command or ls command:
mail
cat /var/spool/mail/root
ls -l /var/spool/mail/root
How to remove root user’s email every day using cron job
Simply run the following cron job:
@daily > /var/spool/mail/root