Michael Bevilacqua on 2 Jul 2009 13:30:48 -0700


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

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


On Thu, Jul 2, 2009 at 3:55 PM, Michael Bevilacqua <michael@bevilacqua.us> wrote:
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):


find . -name script_name -exec chmod 200 {} + ;/


Two additions:

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. Thanks.

 

--
Michael D. Bevilacqua
michael@bevilacqua.us
___________________________________________________________________________
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