Subject: Re: Recursive grep (find, xargs, etc)
To: None <current-users@NetBSD.ORG>
From: Brian C. Grayson <>
List: current-users
Date: 01/29/1996 22:39:37
> Or how about
> netbsd4me:1:34 [/tmp] % ls -l test
> total 0
> -rw-r--r--  1 earle  wheel  0 Jan 23 14:13 This file has spaces in it
> netbsd4me:1:35 [/tmp] % find . -type f -print | xargs egrep -l foo
> egrep: ./test/This: No such file or directory
> egrep: file: No such file or directory
> egrep: has: No such file or directory
> egrep: spaces: No such file or directory
> egrep: in: No such file or directory
> egrep: it: No such file or directory
> or
> netbsd4me:1:36 [/tmp] % touch test/MAE\ User\'s\ Guide
> netbsd4me:1:37 [/tmp] % find . -type f -print | xargs egrep -l foo
> xargs: unterminated quote

  Granted, 'find' and 'xargs' may not handle these files gracefully yet,
but there is a way to tell 'find' to check for these situations -- the -X
option.  From the frequently-used-by-me-because-I'm-a-clueless-newbie man

     -X      The -X option is a modification to permit find to be safely used
             in conjunction with xargs(1).  If a file name contains any of the
             delimiting characters used by xargs,  a diagnostic message is
             displayed on standard error, and the file is skipped.  The delim-
             iting characters include single (`` ' '') and double (`` " '')
             quotes, backslash (``\''), space, tab and newline characters.

  Here's sample output for the situation above:

<marvin>:(10:28pm) test:1 % find -X . -type f -print | xargs egrep -l foo
find: ./This file has spaces in it: illegal path
<marvin>:(10:28pm) test:2 % 
(The MAE\ User\'s\ Guide case is also detected, BTW)
  If nothing else, it's handier to have a one-line error message than a
multiple-line error message that doesn't convey any more information --
less 'warning-bloat' on the screen!  It's also a better error message than
the one that the xargs command would print out.

  Just my $.02.

Brian Grayson (
Graduate Student, Electrical and Computer Engineering
The University of Texas at Austin
Office:  ENS 406       (512) 471-8011
Finger for PGP key.