delete root emails in linux

How to Delete Root Mails in Linux

Most Linux systems have root mailbox at /var/spool/mail/root. It is used to store information about emails & notifications sent by your Linux system. Various services, programs & daemons are tied to this folder to send their notifications to root mailbox. It grows over time and takes up disk space. If you delete the contents of this folder, it can affect the performance of some programs running on your system. So it is important to delete the contents of this file from time to time. In this article, we will learn how to delete root mails in Linux.

How to Delete Root Mails in Linux

Before you implement these steps, please make sure to read the contents of this folder so that you do not delete important e-mails.

For this purpose, login to your terminal as root and execute mail command to automatically open mailbox for reading. Alternatively, you can also use mailx or mailutils for this purpose.

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

The easiest way to delete the root mailbox is to use Linux stdout redirection to the file, which will truncate the mailbox file.

# > /var/spool/mail/root

Another way to do this is to redirect the content of special Linux file /dev/null to root mailbox file. This file is blank and its contents, when redirected to root mailbox file, make it blank too.

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

Once you have truncated the contents of your file, use cat, more or less command to read it, and ensure that it is actually empty. These command should return an end of file (EOF) output.

You can also automate the emptying of root mailbox by setting up cronjob to run regularly. Open crontab with the following command.

# crontab -e

Add the following line to it, to run the file truncation every midnight.

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

In this article, we have learnt how to delete root mailbox in Linux. You can use these commands in most Linux distributions.

Also read:

How to Check if Element is Visible in Viewport
How to Check if Element is Hidden in JavaScript
How to Stay on Same Tab After Page Refresh
How to Select Element By Text in JavaScript
How to Select Element By Name in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *