BillMaier schrieb:
Irgendwie finde ich die find-Syntax sehr gewöhnungsbedürftig. Aber was schlimmer ist: Sie erscheint mir nicht immer logisch.
Warum?
* Wo genau muss denn jetzt die Aktion
-delete
stehen, damit sie ordentlich ausgeführt wird?
In der Manpage
-delete
Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete
fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically
turns on the `-depth' option.
Warnings: Don't forget that the find command line is evaluated as an expression, so putting -delete
first will make find try to delete everything below the starting points you specified. When testing a
find command line that you later intend to use with -delete, you should explicitly specify -depth in
order to avoid later surprises. Because -delete implies -depth, you cannot usefully use -prune and
-delete together.
* Gibt es überhaupt eine grundsätzliche Regel für die richtige Reihenfolge aller Parameter?
In der manpage steht:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
... aber auch:
This manual page documents the GNU version of find. GNU find searches the directory tree rooted at each given
file name by evaluating the given expression from left to right, according to the rules of precedence (see sec‐
tion OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at
which point find moves on to the next file name.
und
-Olevel
Enables query optimisation. The find program reorders tests to speed up execution while preserving the
overall effect; that is, predicates with side effects are not reordered relative to each other. The
optimisations performed at each optimisation level are as follows.
0 Equivalent to optimisation level 1.
1 This is the default optimisation level and corresponds to the traditional behaviour. Expressions
are reordered so that tests based only on the names of files (for example -name and -regex) are
performed first.
Im Wiki finde ich das Beispiel:
find tmp -name "a" -exec touch {} \; -print
Ist nicht -name "a" das, was unter expressions zu verstehen ist?
EXPRESSIONS
The expression is made up of options (which affect overall operation rather than the processing of a specific
file, and always return true), tests (which return a true or false value), and actions (which have side effects
and return a true or false value), all separated by operators. -and is assumed where the operator is omitted.
If the expression contains no actions other than -prune, -print is performed on all files for which the expres‐
sion is true.
Ciao
robert