How to Delete Root Mails (Mailbox) File in Linux

Usually, on a Linux mail server, over the time the size of /var/spool/mail/root file can increase considerably do to various programs, services and daemons that are configured by default to send notifications to root account mailbox.

If the root mailbox file grows in size considerably, you should take into account some measures in order to delete the file in order to free disk or partition space.

However, before actually deleting the root mail messages, first try to read all the root mails in order to make sure that you don’t remove some important e-mail. On console, you can login as root into your system and simply execute mail command which will automatically open root account mailbox for reading. If mail command line utility is not present in your system, install mailx or mailutils package by issuing the below command.

# yum install mailx          [On CentOS/RHEL/Fedora]
# apt-get install mailutils  [On Debian/Ubuntu]

The simplest method to delete the root account mail file is to use Linux stdout redirection to the file, which will truncate the mailbox file, as illustrated in the below example.

# > /var/spool/mail/root

Other variant you can use to truncate the root account mailbox file is to read the content of /dev/null special Linux file (Linux blackhole file) with cat command and redirect the output to root mailbox file, as shown in the below example. Reading the content of /dev/null file will instantly return EOF (End Of File).

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

After truncating the file, inspect the content of the root account mailbox file using cat command, more or less command in order to determine if the content of the file has been successfully erased.

The less command should return END of file immediately.

Truncate File in Linux
Truncate File in Linux

You can automate the process of truncating the root account mailbox file by adding a crontab job to run each midnight as shown in the below except.

# 0 0 * * *  cat /dev/null > /var/spool/mail/root 2>&1 > truncate-root-mail.log

That’s It! If you know any other way of deleting root mailbox, do share with us via comment section below.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Matei Cezar
I'am a computer addicted guy, a fan of open source and linux based system software, have about 4 years experience with Linux distributions desktop, servers and bash scripting.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

3 Comments

Leave a Reply
  1. When I try to run > /var/spool/mail/root, I receive ~Permission Denied~ error.

    How do I get past this???

    This is on Ubuntu 20.04 LTS.

    Reply
  2. I would instead set a .forward in the root home directory to receive root emails on a real account. I think it is bad practice to delete these.

    What you miss could be :

    • security alerts
    • log reports / logwatch
    • updates notifications
    • system health alerts
    • misconfigured tasks error messages and so on.

    Sorry clearly, I’d rather redirect root email to a real mailbox than deleting it.

    Sure, if you first reach it and it is full, then you may need to empty it as a starting point.

    For console based email client, i also like mutt.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.