newbie: to pipe the result of a program as commandlineparameter for another.

Scott W wegster at mindcore.net
Sat Nov 22 07:52:44 PST 2003


Herculano de Lima Einloft Neto wrote:

>  You can use:
>
> find [whatever] -exec rm -rf '{}' \;
>
> or
>
> find [whatever] | xargs rm -rf
>
> Usually, the answer to your question would be: use xargs or put the 
> second command between apostrophes. Something like:
>
> vi `which mozilla`
>
> I think if you use rm -rf `find [whatever]` it might work..
>
> DON'T use these lines unless you're absolutely sure your find will 
> return exactly what you want.. rm -rf is the most destructive Unix 
> command, so if you don't know what you're doing, maybe you should wait 
> a couple of months until you do. :)

Amen ;-)

Seriously, the best thing you can do is just run the 'file listing' or 
'data portion' of any command you're going to pipe together (or use 
-exec, xargs, redirection) by ITSELF, to make sure you're getting the 
expected results, sanity check the results, and THEN using command 
history, bring up the same command and wrap it in backticks or add the 
-exec or | xargs clause to it.

Consider the following, and what would happen if BOTH were executed blindly:
find /tmp -name "jre*" -exec rm {} \;
OK, life's happy, remove all jre* files in the /tmp heirarchy.

find / tmp -iname "jre.*" -exec rm {} \;
Oops, accidently put a space between / and tmp.  Hope you didn't 
actually WANT a working Java/jre on your system!

Sane way:
find /tmp -name "jre*"
check results
If OK, then use the SAME EXACT COMMAND via shell command line editing, 
and just wrap or add to it:
find /tmp -name "jre*" -exec rm -f {} \;

Scott

> Read the man pages for rm, find and xargs so you can understand this.
>
> Best,
> -- 
> Herculano de Lima Einloft Neto <hlen at ig.com.br>
>
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to 
> "freebsd-questions-unsubscribe at freebsd.org"
>




More information about the freebsd-questions mailing list