find: Querying
3.3.3 Querying
--------------
To ask the user whether to execute a command on a single file, you can
use the 'find' primary '-okdir' instead of '-execdir', and the 'find'
primary '-ok' instead of '-exec':
-- Action: -okdir command ;
Like '-execdir' (⇒Single File), but ask the user first. If
the user does not agree to run the command, just return false.
Otherwise, run it, with standard input redirected from '/dev/null'.
The response to the prompt is matched against a pair of regular
expressions to determine if it is a yes or no response. These
regular expressions are obtained from the system ('nl_langinfo'
items YESEXPR and NOEXPR are used) if the 'POSIXLY_CORRECT'
environment variable is set and the system has such patterns
available. Otherwise, 'find''s message translations are used. In
either case, the 'LC_MESSAGES' environment variable will determine
the regular expressions used to determine if the answer is
affirmative or negative. The interpretation of the regular
expressions themselves will be affected by the environment
variables 'LC_CTYPE' (character classes) and 'LC_COLLATE'
(character ranges and equivalence classes).
-- Action: -ok command ;
This insecure variant of the '-okdir' action is specified by POSIX.
The main difference is that the command is executed in the
directory from which 'find' was invoked, meaning that '{}' is
expanded to a relative path starting with the name of one of the
starting directories, rather than just the basename of the matched
file. If the command is run, its standard input is redirected from
'/dev/null'.
When processing multiple files with a single command, to query the
user you give 'xargs' the following option. When using this option, you
might find it useful to control the number of files processed per
invocation of the command (⇒Limiting Command Size).
'--interactive'
'-p'
Prompt the user about whether to run each command line and read a
line from the terminal. Only run the command line if the response
starts with 'y' or 'Y'. Implies '-t'.