[WBEL-users] File deletion

Kirby C. Bohling kbohling@birddog.com
Thu Jan 20 00:02:15 CST 2005


On Wed, Jan 19, 2005 at 06:45:34PM -0500, Luke Scharf wrote:
> On Wed, 2005-01-19 at 17:42, Francies Moore wrote:
> > What I need to do is to remove the files but leave the directories intact.
> > 
> > Is it possible to use a script to do this?  If so, how?  I realise rm 
> > -rf removes subdirectories as well as files!
> 
> The following command should take care of it:
> 	find /some/path -type -f -exec rm -i {} \;
> 
> It will run an individual "rm -i $FILENAME" for each file it finds.  You
> can change the '-i' to a '-fv' or even '-f' if you're brave, but since
> I'm making these instructions for someone else, I'd rather have them
> press "y" 500 times then loose the wrong files!  :-)
> 
> The reason I would do it with find -exec, instead of with backticks ("rm
> -i `find /some/path -type f`") is because the shell only has so much
> space for arguments to a particular command.  When you try to delete
> thousands of files this way, it gives up.  I'm not sure if "|xargs"
> suffers from this problem or not.

xarg's doesn't suffer from this problem.  xargs will just keep
re-executing the program again and again with as many command line
arguments as it can.  In fact, it least to really weird return
values, which makes xargs hard to use in a script reliably (there
are cases where you never get the return code back from the programs
that actually got run).

In fact, xargs is an easy way to take advangte of SMP machines.  I
do this every night in a script (gzip is super reliable in that, you
either have the uncompressed version, the compressed version or
both, you never have a partial compressed and no original in my
experience):

ls *.dbf | xargs -n 1 -P 4 gzip -9

I know my files don't have spaces in the names, so xargs is safe to
use.  That will limit xargs to running 4 processes at once, and
hands each process one argument per process.

It's a good trick for a poor man's parallelization too.  If you have
a 2/4 CPU machine, it's an easy way to get things done on multiple
CPU's if you are CPU bound.

	Kirby





More information about the Whitebox-users mailing list