Ubuntu: How do I delete everything in /var/mail/username from the command line?



Question:

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?


Solution:1

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).


Solution:2

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.


Solution:3

I would argue that you rarely want to delete everything from the mail.

Therefore I would recommend setting up a crontask to run weekly to keep the last 100 lines of each user's mail

cat /var/mail/username | tail -100 > /var/mail/username  

this will keep the last 100 lines


Solution:4

It depends if you have ftp access. If so, just use Nautilus to do a good deal more than any other ftp client. I also use it and Bluefish to edit pages on my websites.

There should be a Mail folder where you can view and delete any and all files.

I find it so much easier than File Manager in cPanel.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »