possible to mark all mail as read using one line terminal?

I am not trying to remove all the mails.

I googled for mark all mail as read, actually got posts saying how to delete them instead.

I found out using echo p | mail will output first of unread then mark it read, but if I do this, I have to loop through them.

I figured for all read mails, they will be appended to a file named mbox

What I am trying to do is...I want to create a bash file which is then used for crontab that let's say, at the end of each month, change the name of mbox into month-year in this way I can keep track and organize the mails BUT in order to have the mails appended into mbox is reading the mails one by one first.

Am I thinking this in a wrong direction? Or can someone give me some advices?

Thanks in advance for any help

EDIT: I am just using sudo apt install mailutils for my ubuntu server


Solution 1:

I was able to do it as follows:

  1. Type mail, it tell me how many unread messages I have. Let's say, 31.
  2. Type t 1-31, it displays all messages from 1 to 31 in a big concatenated sheet (turned out that t * achieves the same result, thanks to Jaime Hablutzel)
  3. Type q to quit view mode, type q again to quit mail

That's it! mail says all 31 messages saved in your mbox file, and next time you enter it, it will say "no mail for you".