≡ 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

Share this tutorial on:
{ 27 comments… add one }
  • Nirmal PathakFebruary 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 TarleaOctober 12, 2010, 11:01 am

      Thanks, it worked!

    • Adam ZiajaSeptember 28, 2011, 10:15 am

      because you need type > before file to clear…

  • CianMarch 31, 2009, 3:55 pm

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

  • KasparSeptember 10, 2009, 8:00 pm

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

  • Md. Mizanur RahmanNovember 4, 2009, 8:44 am

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

  • SunilApril 21, 2010, 7:15 am

    Great thanks for the command

  • //SesslDecember 10, 2010, 2:39 pm

    d 1-x

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

  • KhupcomDecember 12, 2010, 10:55 pm

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

    • fukidOctober 14, 2011, 5:04 am

      It works!!

    • wolviesDecember 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 !!!

  • baanmahaApril 9, 2011, 1:54 am

    Thank you for advice worked..

  • Santosh SheelvantJune 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?

    • Jack O'LanternJuly 30, 2015, 2:43 pm

      Issue this command, as root:

      touch /var/spool/mail/root

  • linux courseJuly 19, 2011, 4:28 pm

    gud information.worked great.

  • MarsJanuary 25, 2012, 9:54 pm

    Use Nirmal’s solution above:

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

  • JFebruary 27, 2012, 10:28 am

    Not the correct way.

    Use biff or edit your .bashrc to add:

    unset MAILCHECK

  • JamesOctober 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.

  • adissFebruary 9, 2013, 10:26 am

    to empty the mail file

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

  • banjoMay 14, 2013, 4:24 am

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

  • Paul ThomsonOctober 5, 2013, 7:04 pm

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

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

  • DaveMarch 2, 2014, 1:59 am

    none of this works

  • AijazMarch 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

    • Jackk O'LanternJuly 30, 2015, 2:47 pm

      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).

  • vietisoApril 4, 2014, 9:04 am
  • murtyJune 24, 2014, 4:52 am

    it works…

  • mf-serviceNovember 11, 2015, 11:41 am

    sudo mail -u username
    On mail-promt type
    :d *

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , ,