Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I purge a linux mail box with huge number of emails? [closed]

Tags:

email

purge

People also ask

How do I empty my whole email box?

Delete all email from a folderIn the Folder pane, right-click the folder that you want to empty, and then click Delete All. When you're prompted to move everything to the Deleted Items folder, click Yes. All the selected items are now in the Deleted Items folder.

How do I delete a root email?

The simplest method to delete the root account mail file is to use Linux stdout redirection to the file, which will truncate the mailbox file, as illustrated in the below example.

Is it safe to delete var spool mail?

Yes, as others have already said, they should be safe to delete, and yes, the best way is with a mail client.

What is mailx in Linux?

mailx helps you read electronic mail messages. It can also send messages to users on your system, but it has no built-in facilities for sending messages to other systems. The command line: mailx [options] user user user ... sends a mail message to the given users.


alternative way:

mail -N
d *
quit

-N Inhibits the initial display of message headers when reading mail or editing a mail folder.
d * delete all mails


You can simply delete the /var/mail/username file to delete all emails for a specific user. Also, emails that are outgoing but have not yet been sent will be stored in /var/spool/mqueue.


Just use:

mail
d 1-15
quit

Which will delete all messages between number 1 and 15. to delete all, use the d *.

I just used this myself on ubuntu 12.04.4, and it worked like a charm.

For example:

eric@dev ~ $ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/eric": 2 messages 2 new
>N  1 Cron Daemon           Tue Jul 29 17:43  23/1016  "Cron <eric@ip-10-0-1-51> /usr/bin/php /var/www/sandbox/eric/c"
 N  2 Cron Daemon           Tue Jul 29 17:44  23/1016  "Cron <eric@ip-10-0-1-51> /usr/bin/php /var/www/sandbox/eric/c"
& d *
& quit

Then check your mail again:

eric@dev ~ $ mail
No mail for eric
eric@dev ~ $

What is tripping you up is you are using x or exit to quit which rolls back the changes during that session.


One liner:

echo 'd *' | mail -N

Rather than deleting, I think we can nullify the file, because the file will be created if the mail service is still on. Something like following will do the job

cat /dev/null >/var/spool/mail/tomlinuxusr

And yes, sorry for awakening this old thread but I felt I could contribute.


On UNIX / Linux / Mac OS X you can copy and override files, can't you? So how about this solution:

cp /dev/null /var/mail/root