in reply to Re^2: Writing unix-style filters
in thread Writing unix-style filters

O' darn it! Use "find ... -print0 | xargs -0 ..." construct already!

In particular (slightly formatted) ...

find -- walk a file hierarchy
.
.
.
-print0
  This primary always evaluates to true.  It prints the
  pathname of the current file to standard output, followed
  by an ASCII NUL character (character code 0).


xargs -- construct argument list(s) and execute utility
.
.
.
-0
  Change xargs to expect NUL (``\0'') characters as separators,
  instead of spaces and newlines.  This is expected to be used
  in concert with the -print0 function in find(1).

Above construct may still fail, on behalf of xargs (see the bottom portion, just after options, of above linked man page), say, if there are "many enough" files. A search on Google Groups produced "maximum command line length <tcsh>".

  • Comment on Passing list long enough for shell expansion to fail, but not for "find | xargs" (was: Re: Writing unix-style filters)

Replies are listed 'Best First'.
Re: Passing list long enough for shell expansion to fail, but not for "find | xargs" (was: Re: Writing unix-style filters)
by polettix (Vicar) on Apr 11, 2007 at 14:47 UTC
    IIRC, there are versions of xargs that call the program multiple times with "chunks" of input if a single command line is too big. Whether this is good for you depends entirely on the application you're writing.

    In this case, anyway, I don't fully get the rationale to use find ... | xargs ... when one can make my_script.pl read filenames directly from standard input. Moreover, setting $/ = "\x00" should do the trick to tandem with find -print0.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.