[olug] Unix Tip: DEALING WITH TOO MANY FILES

mØntar3 m0ntar3 at cox.net
Sat Mar 22 16:47:00 UTC 2003


I just removed like 50k+ files last night actually..

    find /path/to/start/dir -type f -mtime +1 -exec ls -l {} \; -exec rm 
{} \;

This will ignore all files that are not simple files (-type f). Will 
execute command on files with a modification time greater than 1 day 
old. First it executes an "ls -l" and then it executes an "rm" (in case 
maybe you'd like to redirect the output to a file in order to reference 
what file you removed). Then the command does the actual remove of the file.

Proper semantics with the find command say find will not folllow 
symbolic links (I'd have to check about hard links). So infinite 
recursions might not be a worry..

Quinn Coldiron wrote:

>One of the many problems I have with a certain package I support on AIX
>is that they dump and ton and a half of files into a single directory,
>and I can't change that.  I need to clean that out periodically and rm *
>gives me the same error.  Recursively removing the directory and then
>rebuilding the directory is not an option, so I made a shell script to
>do this:
>
>#!/bin/sh
>for i in `ls -1`
>do
>rm $i
>done
>
>Does somebody know of a better way?
>
>Quinn
>
>
>
>On Fri, 2003-03-21 at 13:24, Unix Guru Universe wrote:
>  
>
>>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>>
>>			      UNIX GURU UNIVERSE 
>>			         UNIX HOT TIP
>>
>>			Unix Tip 1906 - March 21, 2003
>>
>>		    http://www.ugu.com/sui/ugu/show?tip.today
>>
>>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>>
>>
>>DEALING WITH TOO MANY FILES
>>
>>In case there are too many files in a 
>>particular directory  and you try doing 
>>
>>$ grep "ABC" *
>>
>>And it fails saying 
>>ksh: /usr/bin/find: 0403-027 The parameter list is too long.
>>
>>what would you do?
>>
>>Well you can do the following:
>>
>>$ls |xargs grep "ABC"
>>
>>This tip generously supported by: puneeta at delhi.tcs.co.in
>>
>>
>>--------------------------------------------------------------------------
>>To Subscribe:    http://www.ugu.com/sui/ugu/show?tip.subscribe
>>To Unsubscribe:  http://www.ugu.com/sui/ugu/show?tip.unsubscribe
>>To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today
>>
>>==========================================================================
>>DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
>>NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX 
>>GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU  ADVISES THAT 
>>ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.
>>
>>Unix Guru Universe - www.ugu.com - tips at ugu.com - Copyright 1994-2001
>>==========================================================================
>>
>>_______________________________________________
>>OLUG mailing list
>>OLUG at olug.org
>>http://lists.olug.org/mailman/listinfo/olug
>>    
>>



More information about the OLUG mailing list