avoiding xargs (Re: [wplug] find & -exec / -ok)

David Ostroske eksortso at linuxmail.org
Fri Sep 26 00:33:22 EDT 2003


Just wanted to share a tip. The original problem was resolved(?), but I
had to share this solution.

I've had a lot of problems with xargs in the past, especially when
handling filenames containing whitespace. I use perl instead:

    find . -name '*.ini' |perl -lne 'unlink'

perl reads the results of the find command (in STDIN), and the -n and -l
options feed the filenames, one at a time, to the "unlink" command here.

It's basically the same as using:
    find . -name '*.ini' -exec rm "{}" \;
except only one perl process is called to remove ("unlink") each of the
files, instead of multiple calls to "rm". Plus, you don't have to worry
about quoting rules. And if you know just a little about perl's
command-line options, it's more intuitive than find's options.

On Thu, 2003-09-25 at 22:32, Keir Josephson wrote:
> On Thursday, September 25, 2003, at 04:15  PM, Vanco, Don wrote:
> 
[...]
> > I expect that this:
> > find . -name *.ini -exec rm {} \;
> > ...will delete all this crap.
> > Further, I expect that
> > find . -name *.ini -ok rm {} \;
> > ....will do the same but prompt me for each deletion.
> >
> > In both cases I get a response that tells me I am not providing an
> > appropriate argument to either -ok or -exec.
> >
> > WTF?
> 
> How about this:
> 
> find . -name '*.ini' | xargs rm -i
> 
> -Keir
> > Don

-- 
David Ostroske <eksortso at linuxmail.org>




More information about the wplug mailing list