How to empty default email account

willdeb

Member
Jul 19, 2012
9
0
1
cPanel Access Level
Root Administrator
I have several default email accounts on my server that grew quite large before I learned how to set them to "fail". They are much too large to clean out using webmail.

How can I clean out these accounts to free space on the server?

Sorry if this has been discussed before. I searched but could not find.

Thanks for your help.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Hello :)

Yes, emails for the default account are stored under the appropriate maildir directory (e.g. cur, new) in "/home/username/mail".

Thank you.
 

willdeb

Member
Jul 19, 2012
9
0
1
cPanel Access Level
Root Administrator
Thank you both. Could you give me an example of the commands needed/

In one case the user is fishhoo and the default mailbox is using over 520 mb.

Thanks again.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
You can utilize the "rm" command to remove files from a directory. Here is an example of how to remove all files from a directory:

Code:
# rm -fv /home/username/mail/cur/*
Remember to use caution when deleting files with the "rm" command as you want to avoid deleting the incorrect file or directory.

Thank you.
 

kernow

Well-Known Member
Jul 23, 2004
1,031
62
178
cPanel Access Level
Root Administrator
Or, go to the file, lets say the "inbox" and run:
Code:
echo -n > inbox
Above command will empty file but not delete it. Will also preserve permissions etc.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Or, go to the file, lets say the "inbox" and run:
Code:
echo -n > inbox
Above command will empty file but not delete it. Will also preserve permissions etc.
Emptying the individual email files is not a good idea if the intention is to delete all of the emails. This would leave the user with several empty emails in their inbox.

Thank you.
 

willdeb

Member
Jul 19, 2012
9
0
1
cPanel Access Level
Root Administrator
Gentlemen,

Sorry, I had to go to a real job. Please understand that I want to empty ONLY the default email accounts. Some of my clients have legitimate email accounts that I do not want to disturb.

Will the above suggestions accomplish that?

Again, thanks for your help.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Yes, the email data for the default email account is mostly stored in the following two directories:

/home/username/mail/cur
/home/username/mail/new

The email data for individual email accounts is stored in the maildir directories within:

/home/username/mail/domain.com/email-account-name

Thank you.
 

willdeb

Member
Jul 19, 2012
9
0
1
cPanel Access Level
Root Administrator
I tried
root@vs1 [~]# rm -fv /home/fishhoo/mail/cur/*

That may have worked, but whem I tried

root@vs1 [~]# rm -fv /home/fishhoo/mail/new/*

I received the message

-bash: /bin/rm: Argument list too long

I assume that did not work.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
You could try a command such as:

Code:
find /home/username/mail/new -name "123*" -exec rm -fv {} \;
Replace the "123*" entry with a prefix of what your files within this directory start with. This is a safeguard so you do not use the command incorrectly and delete files you are not supposed to. Ensure you are careful with the directory that you enter in this command because we do not generally recommend mass deletion of files.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Unfortunately I have no idea what that that prefix might be. I think I will show this thread to my tech support people so they can help.
You could view a list of the files in the directory with a command such as "ls" to see what the file names start with specifically. However, yes, it's a good idea to consult with a qualified system administrator if you are not experienced on the command line. This is especially true when deleting files.

Thank you.
 
Jun 10, 2005
18
1
153
In the past to resolve this kind of issue, i created a script to clean all mailqueue, with some adjustment you can use the same.

#!/usr/bin/perl

my $date = `date`;
chomp $date;

open (LOG, ">>/root/scripts/resetmailqueue.log") || die "Falha ao abrir arquivo ::$!";

print LOG "$date - Apagando fila de mensagens do Exim.......";

if(!system("rm -d -f /var/spool/exim/input/*/*")){
print LOG "[Ok]\n";
}else{
print LOG"[Erro]\n";
}
close (LOG);
 

Data 1

Well-Known Member
May 25, 2008
113
0
66
Columbus Ohio
cPanel Access Level
DataCenter Provider
Old thread I know, and long time no post sorry.

Been moving some very old accounts to my newest array of servers, evidently these accounts were configured in the beginning (not by me) to save everything in the default e-mail address. The one I am working on is 18G.

I too get the bash: /bin/rm: Argument list too long message

ls and dir just set there wondering how they are going to display 18G of files then starts rattling off numbers.
There are several prefixes, all just numbers. There are a lot of each prefix so the command where you put in the prefix could never delete them all.

I probably have about 40 accounts in this condition, ones I assumed from another host who went out of business.

This isn't critical but as root you think you would be able to execute one command and wipe everything out or with google you would be able to find the magic command that would clear the entire directory.

Any new thoughts on this?
Thanks-
 

Data 1

Well-Known Member
May 25, 2008
113
0
66
Columbus Ohio
cPanel Access Level
DataCenter Provider
And experimenting on a home server moments later I find the magic.

Make sure you are IN the directory you want to delete.

find . -type f -print -delete

This will show them to you as it zaps them and takes A LOT LESS TIME than find . -type f -exec rm -v {} \;

In short evidently find has rm built in as -delete

I accept no responsibility for people destroying their entire servers executing commands from my post, please shell responsibly :)
 
Last edited: