[Gllug] C and Unix pioneer Dennis Ritchie reported dead

Philip Hands phil at hands.com
Tue Nov 15 11:49:57 UTC 2011

On Tue, 01 Nov 2011 14:58:40 +0000, James Hawtin <oolon at ankh.org> wrote:
> Personally I hate using -exec (not sure why) and generally do a "find | 
> while read" insted, because a for loop from a glob has a finite number 
> of argument it can handle (however it is very large with linux these
> days).

Just noticed this rather late, and have to note that:

  find | while read ...

doesn't play well with filenames containing line-feeds:

  phil at poker:/tmp$ echo -e "touch 'hello\nthere'" | sh

  phil at poker:/tmp$ find -name hello\* | while read x ; do ls -l "$x" ; done
  ls: cannot access ./hello: No such file or directory
  ls: cannot access there: No such file or directory

which isn't what you want -- rather, one should use NUL terminated
strings using find's -print0, thus:

  phil at poker:/tmp$ find -name hello\* -print0 | xargs -0 ls -l
  -rw-r--r-- 1 phil phil 0 Nov 15 11:30 ./hello?there

BTW xargs has a -I option for when you need to substitute the name in,
but then I don't think you'll get the speed advantage you normally get
with xargs, since it's then needing to do as many execs as find:

  phil at poker:/tmp$ find -name hello\* -print0 | xargs -0 -I{} ls -l {}
  -rw-r--r-- 1 phil phil 0 Nov 15 11:30 ./hello?there

Cheers, Phil.
|)|  Philip Hands [+44 (0)20 8530 9560]    http://www.hands.com/
|-|  HANDS.COM Ltd.                    http://www.uk.debian.org/
|(|  10 Onslow Gardens, South Woodford, London  E18 1NE  ENGLAND
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 851 bytes
Desc: not available
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20111115/2aaf8e29/attachment.pgp>
-------------- next part --------------
Gllug mailing list  -  Gllug at gllug.org.uk

More information about the GLLUG mailing list