In a document created by a former coworker there is this command:

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

It says next to it that it will clean out mailbox.

Can someone please explain how/why these commands do that. I need to know what will happen before I run the command.

We are trying to clean up space on var, as of right now it's at 91%.

  • 2
    It basically truncates /var/spool/mail/root Commented Mar 11, 2015 at 15:30

2 Answers 2


The command will output the data from device /dev/null to the given file (mailbox of the root account). Since /dev/null responds just with end-of-file when reading from it nothing will be written to the file, but with the redirection > the shell will have cleared the file already. Actually this is equivalent to writing just

> /var/spool/mail/root

(i.e., the same without cat or /dev/null).

  • 1
    another alternative (that is probably clearer) truncate -s 0 /var/spool/mail/root.
    – derobert
    Commented Mar 11, 2015 at 16:40

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

Alternative is > /var/spool/mail/root

  • Is there a way I can get all the mail from this and put it somewhere where it can be downloaded and archived as a backup?
    – AllisonC
    Commented Mar 11, 2015 at 15:38
  • Just copy that file /var/spool/mail/root Commented Mar 11, 2015 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .