0

Are -name and -exec options or non-option arguments of find? They look like short options, and they are called find expressions, if I am not mistaken. For example,

find . -name "*.txt" -exec echo {} \;
Tim
  • 101,790

2 Answers2

1

-name, -exec, -print etc. are not option to the find utility but operands. An operand is

An argument to a command that is generally used as an object supplying information to a utility necessary to complete its processing. Operands generally follow the options in a command line.

(from the POSIX definitions), i.e. a non-option that tells the utility what to do (as the file in the command rm file which tells rm what file to delete).

The POSIX standard description of the find utility calls these operands primaries and this is also what they are called on BSD systems.

In the GNU find manual, they are called expressions and are divided into groups depending on their use:

  • Tests (e.g. -name, -mtime)
  • Actions (e.g. -delete, -print)
  • Global options (e.g. -maxdepth, -depth)
  • Positional options (e.g. -follow)
  • Operators (e.g. -not, -and)

The POSIX standard find only has two real options, -H and -L. These has to do with how symbolic links are to be handled.

The POSIX standard does not define any multi-character option or "long option" for any utility. This does no preclude implementations from adding long options though, and GNU utilities in particular are well known for adding expressive long options for extended convenience features.

Kusalananda
  • 333,661
  • Do "option" find expressions work like real options? Is that why they are called options? – Tim Nov 21 '18 at 00:28
  • What is the difference between global options and positional options? – Tim Nov 21 '18 at 00:49
  • tests and actions are find expressions evaluable to true or false. Are option find expressions evaluable, and if yes, also to true or false? – Tim Nov 21 '18 at 01:18
1

The find command has only two options in POSIX (-H, -L), or five in GNU (also -P, -Ddebug_opt, -O#). All other arguments are not options, and thus are non-option arguments.

Notably, options to find precede the paths, while all find expressions should follow them: find [option...] path... [expression...]. (GNU find has some additional primaries that it also calls "options" sometimes, like -maxdepth; they're not true options, appearing inside the expression part, but I suppose the warning messages are more comprehensible if they call them that way).

Michael Homer
  • 76,565