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: http://www.coolcommands.com/index.php?option=com_ccadv&task=display&id=137) 3. cd to the directory where you want to delete the files and execute the following. 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 closedir(INDIR); # 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 Alexander -----Original Message----- From: Alexander [mailto:cloun203@mail.ru] Sent: Tuesday, August 09, 2005 6:08 PM To: 'sunmanagers@sunmanagers.org' 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 Alexander _______________________________________________ sunmanagers mailing list sunmanagers@sunmanagers.org http://www.sunmanagers.org/mailman/listinfo/sunmanagersReceived 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