Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a CentOS 6 server at rackspace with 40GB of space. My server kept crashing with 'no space left on device' errors but there is over 50% free.

When I run df-i this is the output:

/dev/xvda1           2490368 2490351      17  100% /

I traced the problem to postdrop I think. Before I disabled postfix and postdrop the inodes would fill up immediately as soon as I freed any up.

From what I can see, there are thousands upon thousands of files being created in /var/spool/postfix/maildrop. The folder itself is 67MB. I can't "ls" the folder, I've tried to "rm -rf maildrop/" which just hangs for a long time.

How can I remove this folder. I don't even use mail on the server so I've disabled postfix and postdrop and sendmail.

drwx-wx---. 2 postfix postdrop  67M Dec 18 18:25 maildrop 

Just wanted to update:

ls -1 | xargs -I{} rm {}

the above command solved the problem

It took 48 hours on and off. There appeared to be almost 2,000,000 files in the /var/spool/postfix/maildrop folder.

share|improve this question

migrated from stackoverflow.com Jan 14 '13 at 4:01

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted

If you have a directory full of files, normally you can not just remove all files with rm

Try with:

find /path/to/directory -type f -exec rm {} \;

Or try with:

ls -1 /path/to/directory | xargs -I{} rm {}

In other words you have to try to split the command in two, a part that handle the files and another that remove the files.

When you have a zillion of files into one directory you can't remove files using commands like rm. because rm in any case iterate between all files and directory.

share|improve this answer
    
Normally "rm -rf foldername" should just delete the entire folder though. So wouldn't running 'find' and then 'rm' take even longer on that folder. I'm going to assume there are a hundreds of thousands of files in there? – gteh Dec 18 '12 at 18:49
    
what would ls -1 | xargs -I{} rm {} do exactly? – gteh Dec 18 '12 at 18:50
    
Will execute one rm for file, you could also try with ls -1 | xargs rm but some versions of xargs doesn't work well. Can't handle so many files – freedev Dec 18 '12 at 18:56
    
ok thanks, I'll try both methods and see what works. I need to get my ssh session to stop closing after inactivity though otherwise this command will never finish. – gteh Dec 18 '12 at 18:57
1  
I had directories with 300k files... This solution works. – freedev Dec 18 '12 at 18:59

Hmm do you really want to kill your server? So don' t use "\;" in

find /path/to/directory -type f -exec rm {} \;

This command will run a "rm" command for EACH file!

Use the "find" command the right way:

find /directory/ -name ‘*’ -exec rm {} +

this will call the "rm" command only for found files. And your server will thank you! ;) ;) ;)

share|improve this answer

After receiving various errors trying to execute any of the commands freedev suggested, I ended up cleaning it up like this:

rm -f 0*
rm -f 1*
rm -f 2*
[...]
rm -f 9*

You might want to do first a rm -f 00* to estimate how long will it take

share|improve this answer

You must log in to answer this question.