OT: finding every file not in a list

Aryeh M. Friedman aryeh.friedman at gmail.com
Wed Jan 27 19:25:41 UTC 2010


Glen Barber wrote:
> Hi,
>
> Aryeh M. Friedman wrote: 
>   
>> I have a list of files that should be in a dir tree and want to remove 
>> any files from the tree not in list (i.e. if it is on the list keep it 
>> else rm it)... any quick way to do this?
>>     
>
> Perhaps something like this will help:
>
> 	find /dir -type f | \
> 		grep -v `cat excludelist` | \
> 		xargs rm 
>
> Regards,
>
>   
Note quite since it will see every file after the first as a file to be 
grepped instead of filtered out... I was playing with the idea of doing 
a tcsh foreach loop on each file and then using it cut down the output 
of find...  the problem there is it is O(n^2) where is a "good" solution 
is O(n) [I need to do this {don't ask the reasons} everytime I build a 
program I am developing]


More information about the freebsd-questions mailing list