A sintaxe para find
é:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
No seu caso -iname
e -type
são ambas expressões. Portanto, não há problema em usar um antes do outro.
Da descrição:
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 section 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.
- Para
find -type d -iname "*manifest*"
: primeiro teste apenas para o diretório e, em seguida, teste as correspondências de nomes com"*manifest*"
. - Para
find -iname "*manifest*" -type d
: primeiro teste o nome corresponde a"*manifest*"
e, em seguida, apenas ao diretório de teste.
E a execução de ordens diferentes pode resultar em diferenças de desempenho para uma descoberta enorme.
E para otimizar, find
fornece opções de otimização da seguinte forma:
-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. Expres‐
sions are reordered so that tests based only on the names of files (for example -name and
-regex) are performed first.
2 Any -type or -xtype tests are performed after any tests based only on the names of files, but
before any tests that require information from the inode. On many modern versions of Unix, file
types are returned by readdir() and so these predicates are faster to evaluate than predicates
which need to stat the file first.
3 At this optimisation level, the full cost-based query optimiser is enabled. The order of tests
is modified so that cheap (i.e. fast) tests are performed first and more expensive ones are per‐
formed later, if necessary. Within each cost band, predicates are evaluated earlier or later
according to whether they are likely to succeed or not. For -o, predicates which are likely to
succeed are evaluated earlier, and for -a, predicates which are likely to fail are evaluated
earlier.
Para analisar a otimização com sua sintaxe de linha de comando atual, você pode enviá-la para depuração com -D
e obter linha de comando otimizada .
opt Prints diagnostic information relating to the optimisation of the expression tree;
Finalmente find -D opt -type d -iname "*manifest*"
outputs:
Optimized command line:
( -iname *manifest* [0.8] -a [0.4] [need type] -type d [0.4] )