Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 machine running Debian Squeeze with apache, mysql, php... In one of the directories there are some other dirs and way too much files more than 500k files, I tried deleting via WinSCP but it hangs. Even after more than 24 hours WinSCP is still unresponsive. In the moment I am trying to delete this directory with Putty (rm -rf dirname), but just like WinSCP it became unresponsive. Any suggestions? Thanks!

I have root access to the machine.

share|improve this question
Remember, rm doesn't show you what files it's deleting without the -v flag. – Rob Feb 6 '13 at 16:09
up vote 4 down vote accepted

Deleting the directory should work. You might run in to trouble if you are trying to delete individual files because there are so many. You are not running rm -rf dirname/* are you?

My guess is that you are loosing the ssh connection because of inactivity, are you sure the command was not executed correctly on the server?

In any case, a possible workaround would be to use nohup:

nohup rm -rf dirname

You can launch the command and log off, it will continue in the background.


I found this question over at U&L.SE, I recommend you have a look at it. Unfortunately, I cannot recreate your problem. I have made a directory with 2516007 files and could always delete it using rm -rf:

$ mkdir ha
$ for X in $(seq 1 10000);do touch {1..10000}_$X; done
$ ls -f ha | wc -l 
  2516007     <= I stopped before the for loop finished, but this should be enough
$ time rm -rf ha/
  real  23m11.695s
  user  0m3.540s
  sys           0m42.891s

So, it took 20 minutes to delete ~2 million empty files. It seems reasonable that it could take hours to delete a huge amount of non-empty files.

Anyway, some of the suggestions from the U&L question should help. Specifically this one:

find /delb -type f  --delete

or this one (slightly modified from the original)

find /delb -type f -print0 | xargs -0r rm -f

Finally, a trick you could do is delete a few files at a time. If you know that some file names start with the string "foo", others "bar" etc, do this:

rm -rf /delb/foo*
rm -rf /delb/bar*

and so on. You could also try something like this:

for n in {a..z}; do rm -rf /delb/$n*; done
for n in {A..Z}; do rm -rf /delb/$n*; done
for n in {0..9}; do rm -rf /delb/$n*; done

This last command will sequentially delete each file name beginning with each letter of the alphabet, then any file names beginning with numbers.

share|improve this answer
Another alternative would screen but screen isn't always included by default. – Kruug Feb 6 '13 at 14:55
No I am not running rm -rf dirname/* I will try: nohup rm -rf dirname but since this is production server, will it damage it's performance while running and how can I stop it if it fails? – sklr Feb 6 '13 at 16:15
It should not affect the server at all (assuming it is deleting from a local disk). You can kill it by running killall rm or kill $PID where $PIDis the process ID. – terdon Feb 6 '13 at 16:26
I ran nohup rm -rf dirname yesterday (~18 hours ago) and logged off, right now the folder is still existing. – sklr Feb 7 '13 at 10:42
That is a very long time, I'd check dmesg and see if rm is doing several retries because of disk fault. – LtWorf Feb 9 '13 at 23:36

As a side not to the answer already posted. From my experience in dealing with file system that ran out of inodes. With over billion files on the file system.

The fastest way to delete / list files is using find, especially if you have thousands of files / directories. Find starts working immediately provided there is no expansion to do.

find /path/to/be/deleted -type f --delete

Don't use * or any other type of command line expansion as part of your command. * is executed in the terminal before it is passed to the command rm / ls etc. So your terminal sits there trying to list all the hundred thousand files before passing them to the actual command that will do the work. This is very slow.

man bash
Expansion is performed on the command line after it has been split into words. There are seven kinds of expansion performed: brace expansion, tilde expansion, parameter and variable expansion, command substitu‐ tion, arithmetic expansion, word splitting, and pathname expansion.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.