1

I have bunch of mails in my solaris account

107 letters found in /var/mail/icinga, 1 scheduled for deletion, 0 newly arrived
  107  d  2886   MAILER-DAEMON  Fri Jun 11 00:39:39 2010
> 106     2895   MAILER-DAEMON  Fri Jun 11 00:13:02 2010
  105     2890   MAILER-DAEMON  Fri Jun 11 00:10:05 2010
  104     2888   MAILER-DAEMON  Tue May 18 15:13:34 2010
  103     2874   MAILER-DAEMON  Tue May 18 14:58:29 2010
  102     2874   MAILER-DAEMON  Tue May 18 14:28:34 2010

Any idea how can i delete all of them with 1 command line instead of line by line?

1
  • Which mail program? All Solaris releases include mail (not so user friendly) and mailx (slightly more user friendly). Many sites / newer releases also install much more user friendly & powerful command line mail readers such as mutt, elm, and pine (plus of course Thunderbird and Evolution at sites running it as a desktop).
    – alanc
    Nov 30, 2010 at 4:13

6 Answers 6

5
rm /var/mail/${user}
3

mailx has many more features, including batch deleting messages.

use d for the delete subcommand and h to show the headers of messages in the mailbox.

mailx
mailx version 5.0  Type ? for help.


"/var/mail//myuser": 11 messages: 11 new

>N  1 My User        Wed Mar 28 17:50   27/1073  Output from "cron" comman
 N  2 My User        Wed Mar 28 18:56 3226/253350 Output from "cron" comman
 N  3 My User        Wed Mar 28 21:17   24/896   Output from "cron" comman
 N  4 My User        Thu Mar 29 21:17   24/896   Output from "cron" comman
 N  5 My User        Fri Mar 30 17:50   27/1073  Output from "cron" comman
 N  6 My User        Fri Mar 30 18:56 3226/253347 Output from "cron" comman
 N  7 My User        Fri Mar 30 21:17   24/896   Output from "cron" comman
 N  8 My User        Sun Apr  1 21:18   24/896   Output from "cron" comman
 N  9 My User        Mon Apr  2 17:50   27/1070  Output from "cron" comman
 N 10 My User        Mon Apr  2 18:56 3226/253344 Output from "cron" comman
 N 11 My User        Mon Apr  2 21:17   24/893   Output from "cron" comman
> ? d 1-11
> ? h
No applicable messages
? q
2

Not sure if solaris mail is the same as under Linux and can't test right now, but in Linux you would issue the command d 102-107 at the mail prompt (and get a help page if you enter ?).

2
  • it returns 'Illegal numeric'
    – conandor
    Nov 30, 2010 at 2:54
  • 2
    Maybe because 107 is already marked as deleted? Try d 102-106 and see man mail.
    – Sven
    Nov 30, 2010 at 3:01
1

I'm not sure if this works on Solaris (it does under FreeBSD which is mailx afaik), but try d * inside the mail client.

1

Will two commands do?

!>/var/mail/icinga
q
0

Zero out the file with /dev/null.

# cat /dev/null > /var/mail/{user}

1
  • > /var/mail/{user} is enough to create a 0 bytes file. Sep 5, 2019 at 21:00

You must log in to answer this question.

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