find: Unusual Characters in File Names

1 
1 3.3.2.3 Unusual Characters in File Names
1 ........................................
1 
1 As discussed above, you often need to be careful about how the names of
1 files are handled by 'find' and other programs.  If the output of 'find'
1 is not going to another program but instead is being shown on a
1 terminal, this can still be a problem.  For example, some character
11 sequences can reprogram the function keys on some terminals.  ⇒
 Security Considerations, for a discussion of other security problems
1 relating to 'find'.
1 
1    Unusual characters are handled differently by various actions, as
1 described below.
1 
1 '-print0'
1 '-fprint0'
1      Always print the exact file name, unchanged, even if the output is
1      going to a terminal.
1 '-ok'
1 '-okdir'
1      Always print the exact file name, unchanged.  This will probably
1      change in a future release.
1 '-ls'
1 '-fls'
1      Unusual characters are always escaped.  White space, backslash, and
1      double quote characters are printed using C-style escaping (for
1      example '\f', '\"').  Other unusual characters are printed using an
1      octal escape.  Other printable characters (for '-ls' and '-fls'
1      these are the characters between octal 041 and 0176) are printed
1      as-is.
1 '-printf'
1 '-fprintf'
1      If the output is not going to a terminal, it is printed as-is.
1      Otherwise, the result depends on which directive is in use:
1 
1      %D, %F, %H, %Y, %y
1           These expand to values which are not under control of files'
1           owners, and so are printed as-is.
1      %a, %b, %c, %d, %g, %G, %i, %k, %m, %M, %n, %s, %t, %u, %U
1           These have values which are under the control of files' owners
1           but which cannot be used to send arbitrary data to the
1           terminal, and so these are printed as-is.
1      %f, %h, %l, %p, %P
1           The output of these directives is quoted if the output is
1           going to a terminal.  The setting of the 'LC_CTYPE'
1           environment variable is used to determine which characters
1           need to be quoted.
1 
1           This quoting is performed in the same way as for GNU 'ls'.
1           This is not the same quoting mechanism as the one used for
1           '-ls' and 'fls'.  If you are able to decide what format to use
1           for the output of 'find' then it is normally better to use
1           '\0' as a terminator than to use newline, as file names can
1           contain white space and newline characters.
1 '-print'
1 '-fprint'
1      Quoting is handled in the same way as for the '%p' directive of
1      '-printf' and '-fprintf'.  If you are using 'find' in a script or
1      in a situation where the matched files might have arbitrary names,
1      you should consider using '-print0' instead of '-print'.
1 
1    The 'locate' program quotes and escapes unusual characters in file
1 names in the same way as 'find''s '-print' action.
1 
1    The behaviours described above may change soon, as the treatment of
1 unprintable characters is harmonised for '-ls', '-fls', '-print',
1 '-fprint', '-printf' and '-fprintf'.
1