is it safe to delete /var/spool/mail/root

14,199

Solution 1

A more secure way to delete the mails is to use a mail client and delete all the messages.

If you are in debian/ubuntu, you can easily install "bsd-mailx".

with mailx you can delete the messages as follow (as root):

# bsd-mailx
...
& d *
& q

The comman d * deletes all messages and q saves the mailbox and quits mailx. You can delete individual messages, too. See manual of mailx.

There are many other command line mail clients, which could be used.

Solution 2

Yes, as others have already said, they should be safe to delete, and yes, the best way is with a mail client.

But... Take a step back and ask yourself why they are there in the first place.

Is there anything important in there that you should know about?

Whatever sent those emails is still sending emails. For each one, configure it to only send important emails (errors and warnings?), and to an inbox that's not treated as a black hole. Then fix whatever's causing them to be sent.

Solution 3

It's fine to delete it if you don't need it. If you need it then you can tar it and back it up elsewhere.

Share:
14,199

Related videos on Youtube

Simon Ernesto Cardenas Zarate
Author by

Simon Ernesto Cardenas Zarate

Updated on September 18, 2022

Comments

  • Simon Ernesto Cardenas Zarate
    Simon Ernesto Cardenas Zarate over 1 year

    There is a specific server in the company I work that uses sendmail to send multiple emails to sendgrid. The file /var/spool/mail/root is about 4.9 GB, which is taking more than 50% of the disk usage. Now, is it safe to just delete it? or do a

    cp /dev/null /var/spool/mail/root 
    

    to empty it? I don't want to break the email system, and I don't know if emptying that file could make some emails to get lost in the way. I need to delete this file because disk usage is about to get to 95% and I don't want to run out of space. Thank you!

    • Admin
      Admin about 6 years
      You can purge it, emails that are outbound and have not been sent yet will be stored in /var/spool/mqueue. But mailx has d option, read about it in man pages.
    • Admin
      Admin about 6 years
      Yes, but you also should read the mail that comes in, to find out why it is happening.
    • Admin
      Admin about 6 years
      BTW You SHOULD create email alias to redirect email for root to non-privileged user/mailbox.