≡ Menu

Delete all root mail / inbox from a shell prompt

Q. I've CentOS Linux acting as router for our small community based college. I see logwatch and other cron job generating emails for 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.

A. The easilst way is to empty root / users email message file i.e. /var/spool/mail/root or /var/spool/mail/username. Simply type the following command at shell:
> /var/spool/mail/root

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 24 comments… add one }

  • Nirmal Pathak February 19, 2009, 4:03 pm

    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.

    • Jorge Tarlea October 12, 2010, 11:01 am

      Thanks, it worked!

    • Adam Ziaja September 28, 2011, 10:15 am

      because you need type > before file to clear…

  • Cian March 31, 2009, 3:55 pm

    Cheers, had forgotten all anout dev/null, thanks!

  • Kaspar September 10, 2009, 8:00 pm

    You just did oversee the > in front of /var/spool/mail/root
    Works like a charm…

  • Md. Mizanur Rahman November 4, 2009, 8:44 am

    Thank boss……..it’s an important command

  • Sunil April 21, 2010, 7:15 am

    Great thanks for the command

  • //Sessl December 10, 2010, 2:39 pm

    d 1-x

    d = delete
    1-x = mail 1 to mail x (e.g. d 1-53)

  • Khupcom December 12, 2010, 10:55 pm

    Here the simple way to delete all mail
    echo ‘d *’ | mail -N

    • fukid October 14, 2011, 5:04 am

      It works!!

    • wolvies December 12, 2011, 9:29 am

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

      thanks from now !!!

  • baanmaha April 9, 2011, 1:54 am

    Thank you for advice worked..

  • Santosh Sheelvant June 2, 2011, 7:36 am

    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?

  • linux course July 19, 2011, 4:28 pm

    gud information.worked great.

  • Mars January 25, 2012, 9:54 pm

    Use Nirmal’s solution above:

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

  • J February 27, 2012, 10:28 am

    Not the correct way.

    Use biff or edit your .bashrc to add:

    unset MAILCHECK

  • James October 9, 2012, 11:05 am

    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.

  • adiss February 9, 2013, 10:26 am

    to empty the mail file

    #cp /dev/null /var/mail/root

  • banjo May 14, 2013, 4:24 am

    Can i eat near my Linux server or is this bad practice?

  • Paul Thomson October 5, 2013, 7:04 pm

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

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

  • Dave March 2, 2014, 1:59 am

    none of this works

  • Aijaz March 16, 2014, 7:25 am

    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

  • vietiso April 4, 2014, 9:04 am
  • murty June 24, 2014, 4:52 am

    it works…

Leave a Comment