B20.1: Problem with recursive rm (rm -r) on Windows98

13mb80000-HallM(DR3132)37x10 marcus@bighorn.dr.lucent.com
Tue Aug 31 23:49:00 GMT 1999

> > To do what
> > you want you need to create a foreach loop using find and rm.
> > 
> > E.G.:
> > foreach FILE in `find . -name *.d`; do rm -f $FILE; done
> That command will fail if there are too many files ending in `.d',
> due to fixed limits on the length of a command line.
> A more robust (and more concise) alternative is to use
> 	find . -name *.d | xargs rm -f

also, that executes the rm command fewer times, so there is less process
creation/deletion overhead involved.

If you needed to do something more complex than just a single command,
and you need the power of the shell to manipulate whatever files you
are finding, another construct that is handy is:

find . -name *.d | while read i;do rm -f $i;done

BUT..  be sure that whatever commands you execute do not read from standard
in (i.e. be careful about executing "rsh ..." since it reads its standard
input and starts shipping to the remote machine, it will suck up the rest
of the input file names).  Such commands should be given a flag to stop
reading standard input (e.g. "rsh -n ...") or have their input re-directed
from /dev/null.

Still, if it is something that can be done by stringing arguments with
xargs, that's by far the safest and most efficient way to do it.


Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

More information about the Cygwin mailing list