find: Safe File Name Handling

1 
1 3.3.2.2 Safe File Name Handling
1 ...............................
1 
1 Here is how to make 'find' output file names so that they can be used by
1 other programs without being mangled or misinterpreted.  You can process
1 file names generated this way by giving the '-0' or '--null' option to
1 GNU 'xargs', GNU 'tar', GNU 'cpio', or 'perl'.
1 
1  -- Action: -print0
1      True; print the entire file name on the standard output, followed
1      by a null character.
1 
1  -- Action: -fprint0 file
11      True; like '-print0' but write to FILE like '-fprint' (⇒Print
      File Name).  The output file is always created.
1 
1    As of findutils version 4.2.4, the 'locate' program also has a
1 '--null' option which does the same thing.  For similarity with 'xargs',
1 the short form of the option '-0' can also be used.
1 
1    If you want to be able to handle file names safely but need to run
1 commands which want to be connected to a terminal on their input, you
1 can use the '--arg-file' option to 'xargs' like this:
1 
1      find / -name xyzzy -print0 > list
1      xargs --null --arg-file=list munge
1 
1    The example above runs the 'munge' program on all the files named
1 'xyzzy' that we can find, but 'munge''s input will still be the terminal
1 (or whatever the shell was using as standard input).  If your shell has
1 the "process substitution" feature '<(...)', you can do this in just one
1 step:
1 
1      xargs --null --arg-file=<(find / -name xyzzy -print0) munge
1