[plug] rm of contents

Matt Kemner zombie at penguincare.com.au
Mon Mar 17 11:50:03 WST 2003


On Mon, 17 Mar 2003, quoth Trevor Phillips:

> On Sunday 16 March 2003 20:00, Cameron Patrick wrote:
> > On Sun, Mar 16, 2003 at 07:46:03PM +0800, Leon Brooks wrote:
> > | > find dir -type f -print0 | xargs -0 rm
> > |
> > | find dir -type f -exec rm -f {} \;

> The second will take more system resources, as it runs rm once for each file,
> instead of running it once for all files.

I tend to use:

for FILE in `find dir .....`
do
  <command>
done

Does the same as the 2nd command above, but (to me) is easier to read
and has the added bonus of easily allowing multiple commands to be run for
each file.

Also, for the original problem it would be better to use:

find $dir ! -type d

rather than  -type f

because that way you get everything except the directories, including
symlinks, devices, pipes etc, not just regular files.

 - Matt



More information about the plug mailing list