SUMMARY: shell question

From: Alexander <>
Date: Wed Aug 10 2005 - 03:52:20 EDT
HI all,

I've got so many perfect answers from all of you. 
In general there are 5 ways to remove many files from a directory.

1. Easiest way is to "rm -r" the directory and then recreate it. Will help
save additional disk space as well as help performance on finding files in
the new directory as well. 

2. ls | xargs rm {} (More info on xargs:

3. cd to the directory where you want to delete the files and execute the

for x in `ls`; do rm $x ; done

4. cd <workdir>
find . -depth -print -exec rm -rf {} \;

5. And very exotic way but still working (have not tried)
#! /usr/bin/perl
# set $dirname equal to /path/to/directory 
$dirname = "/path/to/directory"; 
# open dir for reading 
opendir (INDIR,"<$dirname"); 
# read the dirhandle into array called @dirlist 
@dirlist = readdir(INDIR); 
# close the dirhandle 
# move to the appropriate directory 
chdir $dirname; 
# now nuke any file in the @dirlist unless starts with .
# or die on failure to delete and report error details 
foreach $file(@dirlist) {
	unless ($file =~ /^\./) {
		unlink $file || die "couldn't delete $file: $!\n";

Best regards

-----Original Message-----
From: Alexander [] 
Sent: Tuesday, August 09, 2005 6:08 PM
To: ''
Subject: shell question

Hi All,

I've got some tricky question.
Assume you need to remove all files from a directory

You issue 
#rm -rf *

But if you need to remove a million files. I suppose that in some shells it
won't work

The question. Is there any way to remove a big amount of files.

Best Regards
sunmanagers mailing list
Received on Wed Aug 10 03:53:05 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:50 EST