Delete all root mail / inbox on Linux / Unix from a shell prompt

last updated in Categories , , , , , ,

I have CentOS Linux acting as a router for our small community-based college. I see logwatch and other cron job generating emails for the root account. How do I delete those emails? I don’t want to disable email facility but just wanted to get rid of all root emails. How do I delete root user mails (mailbox) file in Linux or Unix like system?

The easiest way is to empty root or users email message file. The file is located at/var/spool/mail/root or /var/spool/mail/username location. You can read mail using mail/mailx command. It is an intelligent mail processing system, which has a command syntax reminiscent of ed with lines replaced by messages.


How to install mail command on Linux

Type the following yum command on a CentOS/RHEL to install the same:
sudo yum install mailx
Use the following dnf command on a Fedora Linux to install it:
sudo dnf install mailx
Try the following apt command/apt-get command on an Ubuntu or Debian system:
sudo apt install mailutils

How do I read my mail messages from the CLI on Linux?

Simply type the following command:
How to view root user email on Linux or Unix using mail command
The current message is initially the first message (numbered 1) and can be printed using the print command which can be abbreviated p. Just press p. The user can move among the messages much as he moves between lines in ed, with the commands + and - moving backwards and forwards, and simple numbers. Just type 10 to read email message # 10. After viewing a message the user can delete by pressing d. To reply press r.

How to delete root user’s mailbox/inbox file in Linux or Unix

Simply type the following command at shell prompt to delete all root mail:
> /var/spool/mail/root
Verify it with the following command or cat command or ls command:
cat /var/spool/mail/root
ls -l /var/spool/mail/root

How to delete all root mail command in Linux or Unix

How to remove root user’s email every day using cron job

Simply run the following cron job:
@daily > /var/spool/mail/root


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at

Historical Comment Archive

27 comment

  1. Nothing happens when I type /var/spool/mail/root to purge the root user’s mail messages.

    I think you meant,

    #cat /dev/null > /var/spool/mail/root

    — Nirmal.

    1. I’ve tried that but received this message: ‘Value too large for defined data type’ :-(
      can anybody help me?

      thanks from now !!!

  2. I have deleted the file “root” from /var/spool/mail itself and from then on nobody is receiving the emails upon our transactions.

    Please suggest me a solution if any?

  3. You can’t cat /dev/null; it is a block special device. It also outputs nothing and closes right away; it is the same as the original post in concept. the Null device is a place to output stuff you don’t want, its opposite would be ‘/dev/zero’. The original one doesn’t work because it is unbalanced- there is nothing going into the file.

    ‘exit > /path/to/file’

    Is basically what the cat /dev/null does. You want

    echo > /path/to/file. instead.

  4. Fantastic! – Just cleared 35000 unread mail items ;-)

    Keep up the good work, stay safe!
    Paul :-)

  5. what will be the impact if I use the command for oracle file which is more than 3 gb .If there is no bad impact ,can i execute on Production server,can I get any script

    cat /dev/null > var/spool/mail/oracle

    1. This will delete the mail messages for user ‘oracle’, leaving the file intact as a zero-byte file. If you don’t need the messages, this is safe to do. HOWEVER, you should get into the habit of saving this file off somewhere before you issue this command (ftp the file to your local machine, then put it on a disk or something…just in case you need to refer to it later).

    Still, have a question? Get help on our forum!