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?
Asked
Active
Viewed 4,474 times
2 Answers
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.
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 range123
to234
.
References:

pa4080
- 29,831
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
~d>30d
no spaces. – Martin T. Nov 09 '20 at 08:32