[TriLUG] find and rm command

Tobias Gloth gloth at geomagic.com
Thu Jul 15 15:54:14 EDT 2004


On Thu, Jul 15, 2004 at 03:09:56PM -0400, Jojo Almario wrote:
> This should be a relatively simple one, but I am having a little trouble
> making it all fit together.  Im trying to search through some
> directories with the "find"  command and delte any file within any
> folder that has the name "thumbs.db"  This is what I came up with so
> for.
> 
>  
> 
> Find /home/directory/ -name thumbs.db -exec rm {}/ -rf
> 
>  
> 
> It either times out or tells me Im missing something in the -exec
> command.  Im going to keep perusing the man page, but I wanted to see if
> any one could get this faster than my feeble skills would allow.

Two thoughts:

The "-exec rm {}" part will run rm once for every file that's found. This
is a bit heavy on the ressources.  Just print the file names to stdout, and
use "| xargs rm" on them.

Also, as others have said, with combinations of find and rm, it's good to
be paranoid.  So, leave away the -r on rm.  It's also good practice to only
find files and skip directories.

So, this might be a better solution:

find /home/directory -name thumbs.db -type f -print | xargs rm -f

-Tobi





More information about the TriLUG mailing list