Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Nov 2003 10:52:38 -0500
From:      Scott W <wegster@mindcore.net>
To:        Herculano de Lima Einloft Neto <hlen@ig.com.br>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: newbie: to pipe the result of a program as commandlineparameter for another.
Message-ID:  <3FBF8646.7030905@mindcore.net>
In-Reply-To: <3FBF67F5.1020704@ig.com.br>
References:  <3FBF67F5.1020704@ig.com.br>

next in thread | previous in thread | raw e-mail | index | archive | help
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@ig.com.br>
>
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to 
> "freebsd-questions-unsubscribe@freebsd.org"
>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FBF8646.7030905>