3

I have a whole lot of mail in my /var/mail/user file. Is there some way I can delete all the mail generated in 2016 only?

pa4080
  • 29,831
J. Doe
  • 41

2 Answers2

5

You can use mutt for this purpose. It is a small but very powerful text based program for reading and sending electronic mail:

sudo apt install mutt 

The steps are:

  • Run mutt in to a terminal.

  • Press Shift+D - delete-pattern - delete messages matching a pattern.

  • Type the pattern: ~d 01/01/2016-31/12/2016 and press Enter. You could use also the pattern ~d 1/16-12/16. Where ~d [MIN]-[MAX] means messages with “date-sent” in a Date range.

  • Press q and then hit Enter again.

enter image description here

Other useful patterns according to the current topic could be:

  • ~d>30d - will delete the messages older than 30 days.
  • ~m 120-234 - will delete the messages with numbers in the range 123 to 234.

References:

pa4080
  • 29,831
  • 1
    The pattern is ~d>30d no spaces. – Martin T. Nov 09 '20 at 08:32
  • Hi, @MartinT. Thanks for the comment. Probably at the version I've made the tests 3 years earlier the syntax was with spaces. However, if you find this answer useful, don't forgot to upvote. – pa4080 Nov 09 '20 at 10:39
0

You might be able to use procmail to generate a new file. Normally you would file your mail as you work.

There are a number of email clients that you can use. Many allow you to select multiple messages to file or delete.

BillThor
  • 4,698