find . -print0 | xargs -0 echo2007年05月16日 20時28分37秒

いまどきfindとxargsを使う時は-print0と-0を忘れずに

ディレクトリ名に0x20(空白)が入るMac OS X環境でfindに-print0を使わずにxargsで受け取るのはヤバい。


% man find
     -print  This primary always evaluates to true.  It prints the pathname of
             the current file to standard output.  If none of -exec, -ls,
             -print0, or -ok is specified, the given expression shall be
             effectively replaced by ( given expression ) -print.

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


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

これは知らなかった。普段は空白を含まないから全然問題になってなかったので。