61

As a result of a long-running cron job, I have over 1,000 messages in my user's mailbox. What's the easiest way to delete them?

G__
  • 713

2 Answers2

101

If you want to delete all the messages, you can simply truncate the mailbox file for a user with the following command:

> /var/mail/username

(the greater than sign is not a prompt: you are in effect redirecting the output of nothing to the file, which will truncate it).

14

Run mail in a terminal. Press d 1-. This will delete those messages.

Removing files for managing mail is like adjust the volume of your tv with a hammer. It may work, but it is not optimal and far too brutal.

vidarlo
  • 22,691
  • 1
    This is the correct answer. It also allows deleting just some emails, if it's unclear from the command. E.g. d 1-100 will delete the first 100 email messages. – texnic May 20 '17 at 07:19
  • 1
    I had to install mailutils and then use d * on Ubuntu 12.04 – Leslie Viljoen Jul 22 '19 at 03:19
  • It was d * on centos 8 after installing mailx – james-see Jun 21 '21 at 20:25
  • When I type mail, I get the message "No mail for " and cannot access the mail console – Aisteru Firë Dec 04 '22 at 14:43
  • @AisteruFirë What are you attempting to do? I have a feeling that you should ask a new question, where you explain in some more detail, because you probably don't want to delete mail. – vidarlo Dec 04 '22 at 14:47
  • @vidarlo I saw the "You have new mail" message on login, used mail to read it, then quit. I got the message that the message was stored in $HOME/mbox, and wanted to go and delete it. I realized that this was a simple file, so I just deleted it, but before doing so I thought I had to go back through mail to delete it. – Aisteru Firë Dec 05 '22 at 15:02