When I checked my FreeBSD system mail box today, I found that there were 8000 system mails sitting my mail box:
Mail version 8.1 6/6/93. Type ? for help. "/var/mail/root": 8182 messages 8182 new >N 1 email@example.com Fri Sep 30 03:02 44/1330 "x.com output" N 2 firstname.lastname@example.org Fri Sep 30 03:02 72/2464 "x.com output" N 3 email@example.com Sat Oct 1 03:01 35/1075 "x.com output" ... Another 8000 lines go here
There are several ways you can do. Either you can go through them one by one and delete them one at a time, i.e.,
d [Hit the ENTER Key]
Or specify which mails you like to delete by ID, e.g.,
d x-y [Hit the ENTER Key]
where x and y are the start and end of the mail ID, respectively.
For example, if you want to empty your FreeBSD mail box, you can do the following:
d 1-8182 [Hit the ENTER Key]
where 8182 is the number of mails I have.
You can find the number of your emails when you open your mail box:
"/var/mail/root": 8182 messages 8182 new
Hit the enter key again to confirm that the mail box is empty:
And leave the mail box.
Now, try to access your mail box again, and the system should tell you that you have no system mail.
# mail No mail for root
How to stop generating the system mails
Whenever the system run a background job, it will store the output of the program and email to the system mail box for auditing purposes. However, you can disable this feature if you don’t care the output.
Normally, we run a script this way:
To avoid any output, we do the following instead:
start.sh > /dev/null 2>&1
For example, if you run many cron jobs, you need to go over your cron job list and add this to every single script, i.e.,
sudo nano /etc/crontab or crontab -e
and add /dev/null 2>&1 to every command.
Hope it helps.