Note that POSIX find does support options like other commands, and --
to mark the end of them like other commands. Those are -H
and -L
.
The -print
, -type
... are not options, they're sometimes called predicates. They are arguments whose order matters that appear after the file paths which themselves appear after the options. You've also got (
and !
. Together, they build an expression that is used to determine what files to find.
find
is not the only one. [
(aka test
) and expr
are other commands whose arguments are used to build an expression.
Like find
, [
has operators that start with -
and are more than one-letter (-gt
, -eq
...).
Like find
, test
has issues where those operators may be confused with operands.
find -- "$file1" "$file2" -type f
[ -f "$file1" -a -f "$file2" ]
If $file2
is !
, it's a problem with find
. If it's =
, it's a problem with (some) [
.
For all of find
, test
and expr
, using options to build the expression would not really have worked. Another option could have been to have one string evaluated as the expression like awk
or sed
. like for
find f1 f2 \( -type f -mtime -1 -o ! -type f -newer x \) -exec ls -ld {} +
Do:
find 'found = 0
if (typeof($f) == "f") {
if (age($f) > 1) found=1
} else if (age($f) < age("x")) found = 1
if ($found) exec_multi("ls -ld {}")' f1 f2
But that means implementing a grammar parser in find
. That also means potential quoting nightmare for the "x"
and command line above.
Actually AT&T Research did come up with such a command: tw (tree walker), but even though it's now open source, I'm not aware that it is really used out of AT&T.