JP Vossen on 3 Jul 2009 11:27:38 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] add symlink to directory with find -name -exec {} \;


> Date: Thu, 2 Jul 2009 15:55:22 -0400
> From: Michael Bevilacqua <michael@bevilacqua.us>
> 
> On Thu, Jul 2, 2009 at 3:39 PM, JP Vossen <jp@jpsdomain.org> wrote:
> 
>> In general you want to avoid using '-exec {} \;' because it's terribly
>> inefficient since it guarantees that you spawn a sub-shell for every
>> single file you find.  *Often* a better way is this (assume GNU tools):
>>        find -name script_name -print0 | xargs -0 chmod 200
> 
> Note, there is a way to perform this in find(1) without piping to xargs(1):

<snip>
 > 1) find(1) doesn't require the ; at the end (see example 2) when 
using > the +, and I botched writing that anyways. Haste makes waste. My 
bad.
 >
 > 2) time shows benchmarking between the two:
 >
 > cd /
 > $ time find . -iname '*te*' -print0 | xargs -0 file
 > real    0m12.303s
 > user    0m11.089s
 > sys     0m0.812s
 >
 > $ cd /
 > $ time find . -iname '*te*' -exec file {} +
 > real    0m12.070s
 > user    0m10.981s
 > sys     0m0.632s
 >
 > They perform relatively the same. Just one is shorter to write.

Cool.  I'd noticed the '+' in the man page but didn't read into it 
enough.  I bet yours is a bit faster because it doesn't have to spawn a 
sub-shell at all.  :-)

But, mine deals with file names with spaces, yours doesn't.  Quoting the 
'{}' does not seem to work when using echo to test.  Old-school Unix 
folks will argue that you shouldn't use spaces in names anyway.  I'd 
like to agree, but the problem with that approach is that it doesn't 
work anymore, when you start looking at your music library or VMware 
default (/var/lib/vmware/Virtual\ Machines/) or if you are on, say, a Mac.

Later,
JP
----------------------------|:::======|-------------------------------
JP Vossen, CISSP            |:::======|      http://bashcookbook.com/
My Account, My Opinions     |=========|      http://www.jpsdomain.org/
----------------------------|=========|-------------------------------
"Microsoft Tax" = the additional hardware & yearly fees for the add-on
software required to protect Windows from its own poorly designed and
implemented self, while the overhead incidentally flattens Moore's Law.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug