Deleting mail with mail

by bitznbitez

Many times, such as today, you run across a user account with a bazillion old system generated emails that you want to delete on a unix ( aix, linux, solaris, whatever ) server.   It doesn’t have any civilized mail reading programs installed.

Use the mail program as follows in this example.

[vincent@blackwater ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/vincent": 7 messages 6 new 7 unread
 U  1 vincent@blackwater  Mon Jun 18 10:42  54/2366
>N  2 vincent@blackwater  Mon Jun 18 10:43  53/2356
 N  3 vincent@blackwater  Mon Jun 18 10:43  53/2356
 N  4 vincent@blackwater  Mon Jun 18 10:43  53/2356
 N  5 vincent@blackwater  Mon Jun 18 10:43  53/2356
 N  6 vincent@blackwater  Mon Jun 18 10:43  53/2356
 N  7 vincent@blackwater  Mon Jun 18 10:43  53/2356
& d 1-7
& quit 
[vincent@blackwater ~]$ mail
No mail for vincent
[vincent@blackwater ~]$

The key is the numbers following the d command.  They list a range.  So d 1-7 deletes emails number 1-7.

Advertisements