[LUAU] How do you delete over 500,000 files in a directory

Jim Thompson jim at netgate.com
Thu Nov 3 12:12:58 PST 2005


Clifton Royston wrote:

>On Thu, Nov 03, 2005 at 09:23:54AM -1000, Matt Darnell wrote:
>  
>
>>Aloha,
>>
>>We have a box with over 500,000 files in a direcotry. If I try 'rm m*' I get
>>an error, something like 'too many arguments'
>>    
>>
>...
>  
>
>>All the files start with mgetty. I would like to prserve the other files in
>>the directory and the directories below /var/log
>>    
>>
>
>  ls | grep '^mgetty' | perl -nle 'unlink;'
>
>  find . -name 'mgetty*' -maxdepth 1 -print | perl -nle 'unlink;'
>
>  find . -name 'mgetty*' -maxdepth 1 -print | xargs rm
>
>  ... and numerous variations you can probably think of now that you've
>got the idea.  Just avoid anything which requires the shell to do
>globbing and you'll be fine.
>  
>
or cut down on the amount of globbing that the shell does in any one pass.
If all the files end in a number, (and the numbers are well-distributed)

#!/bin/bash
i="0"
while [ $i -le 9 ]
do
echo mgetty*$i | xargs rm -f
i=$[$i+1]
done




More information about the LUAU mailing list