File deletion problems

Dave Howorth dhoworth at mrc-lmb.cam.ac.uk
Wed Apr 14 09:40:09 UTC 2010


J wrote:
> On Tue, Apr 13, 2010 at 13:25, MirJafar Ali <mirjafarali at gmail.com>
> wrote:
>> Hello,
>> 
>> 
>> I am not quite sure if this is appropriate question to this
>> question here.
>> 
>> 3-4 days I wrote some program which had some problem, therefore
>> created about 1 million small files in one directory. 3 days back I
>> have the comman \rm -rf <Directoryname and still the code running.
>> When I see the "top" it shows that only 1% CPU is utilized.
>> 
>> 
>> I am not sure where things are going wrong. There is no other
>> activity other than \rm -rf command. Do why does "remove" takes so
>> much time. I am sure that creation didn't take that much time.

rm is not a CPU-intensive command. More interesting is disk usage. How
much does top show for 'waiting' ('wa'). You don't say how fast your
disk is or what type of filesystem you have. That will make a big
difference. But I've certainly had a machine take over a day when
deleting millions of files, so what you're seeing is not impossible.

Another way to check what rm is doing is to use strace -p to see what
system calls it is making. Or use du to see how much disk is free.

> Why don't you kill the command and check in the directory... or look 
> in /var/log/syslog and see if there are any error messages.
> 
> or open one terminal and run this command:
> 
> #watch --inverval=1 'ls path/to/directory | wc -l'

You're joking right? An ls of the directory will take way longer than a
second! Trying to ls directories with millions of files is a waste of
time. mirjafarali, if you've done this, just find and kill the processes.

> and in another terminal:
> 
> #rm -f /path/to/directory/*

The rm -f * won't work because the shell will try to expand the
directory listing. You need an rm -r on the directory as the OP already
said he was using.

Cheers, Dave




More information about the ubuntu-users mailing list