Re: find - simple Python example (+ aliases)

Uttam M. Narsu (narsu@styx.hks.com)
Wed, 6 Apr 1994 18:25:15 -0400

On Apr 6, 8:49am, Mike Tibbs wrote:
> Subject: Re: find - simple Python example (+ aliases)
>
> For those of you who like aliases, here's some handy ones to make using 'find'
> a little easier from csh.
>
> #
> # find aliases
> #
> # find big, old, new, dirs, links, man? files
> alias findbig 'find . -size +1000 -exec ls -lF {} \;'
> alias findold 'find . -atime +125 -exec ls -lF {} \;'
> alias findnew 'find . \( -ctime -1 -type f \) -exec ls -lF {} \;'
> alias findtod 'find . -ctime 0 -print' # today
> alias finddirs 'find . -type d -exec ls -ldF {} \;'
> alias findlinks 'gfind . -type l -maxdepth 1 -print0 -printf "\t%l\n"'
> alias findlinksdeep 'gfind . -type l -print0 -printf "\t%l\n"'
> alias findman 'find / -type d -name "man?" -exec ls -ldF {} \;'
> # find filename, file with word, file with expression
> alias findfile 'find . -name "\!*" -exec ls -ldF {} \;'
> alias findword 'find . -type f -exec grep -wil -e "\!*" {} \;'
> alias findwords 'find . -type f -exec grep -wi \!:1 {} /dev/null \;'
> alias findexp 'find . -type f -exec grep -il -e "\!*" {} \;'
> alias findexps 'find . -type f -exec grep -i \!:1 {} /dev/null \;'
>-- End of excerpt from Mike Tibbs

Mike,

You can speed up your find commands by an order of magnitude by using xargs.
The problem with -exec is that it uses (like most makes) a shell for every
command. It also does poorly when there is a huge amount of output from the
find.

As an example, if we rewrite:
find . -type d -exec ls -ldF {} \;
as:
find . -type d -print | xargs ls -ldF

we find quite a bit of speedup:

3.222u 11.121s 0:21.74 65.9% 0+0k 161+0io 9pf+0w
3.238u 11.210s 0:20.26 71.2% 0+0k 52+2io 14pf+0w

vs:

0.297u 1.686s 0:02.30 85.6% 0+0k 24+1io 6pf+0w
0.282u 1.673s 0:02.18 89.4% 0+0k 5+0io 4pf+0w

(Note to time the above I had to put both find commands in shell scripts; time
doesn't like timing things with a pipe)

The only drawback to using xargs vs. -exec, is the problem with pipes: it can
take a while before the pipe is filled an you see some output. But the speedup
is usually worth it.

xargs is quite versatile. It can do inserts with the braces (like find) and it
can even pass a fixed number of arguments to each invocation of the command
passed to it. Check out the man page.

-uttam

-- 
+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+
| Uttam M. Narsu                      E-mail: narsu@hks.com          |
|                                                                    |
| Hibbitt, Karlsson & Sorensen, Inc.    Tel:  (401) 727-4200 x 4442  |
| 1080 Main Street, Pawtucket RI 02860  Fax:  (401) 727-4208         |
+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-=+