Acho que eu faria assim:
find -mindepth 3 -type d ! -path '*/p/*' -name c -print
Com base no feedback de @StephaneChazelas, acredito que esse método eliminaria a pesquisa externa em qualquer diretório /p/
:
find -mindepth 3 -type d -path '*/p/*' -prune -o -name c -print
Analisando uma descoberta
Para comparar os comandos de localização, você pode adicionar a opção de depuração -D search
, para que você possa ver o desempenho de uma determinada descoberta em relação a outra.
Corri o comando do @StephaneChazelas contra o meu para ver onde estavam as diferenças. Os dois comandos são executados e sua saída é executada em sdiff
abaixo:
$ sdiff \
<(find -D search -mindepth 3 -type d -path '*/p/*' -prune -o -name c -print 2>&1) \
<(find -D search -type d -name p -prune -o -path './*/*/*' -name c -print 2>&1)
consider_visiting (early): '.': fts_info=FTS_D , fts_level= 0 consider_visiting (early): '.': fts_info=FTS_D , fts_level= 0
consider_visiting (late): '.': fts_info=FTS_D , isdir=1 ignor | consider_visiting (late): '.': fts_info=FTS_D , isdir=1 ignor
consider_visiting (early): './a': fts_info=FTS_D , fts_level= consider_visiting (early): './a': fts_info=FTS_D , fts_level=
consider_visiting (late): './a': fts_info=FTS_D , isdir=1 ign | consider_visiting (late): './a': fts_info=FTS_D , isdir=1 ign
consider_visiting (early): './a/c': fts_info=FTS_D , fts_leve consider_visiting (early): './a/c': fts_info=FTS_D , fts_leve
consider_visiting (late): './a/c': fts_info=FTS_D , isdir=1 i | consider_visiting (late): './a/c': fts_info=FTS_D , isdir=1 i
consider_visiting (early): './a/c/d': fts_info=FTS_D , fts_le consider_visiting (early): './a/c/d': fts_info=FTS_D , fts_le
consider_visiting (late): './a/c/d': fts_info=FTS_D , isdir=1 consider_visiting (late): './a/c/d': fts_info=FTS_D , isdir=1
consider_visiting (early): './a/c/d/e': fts_info=FTS_D , fts_ consider_visiting (early): './a/c/d/e': fts_info=FTS_D , fts_
consider_visiting (late): './a/c/d/e': fts_info=FTS_D , isdir consider_visiting (late): './a/c/d/e': fts_info=FTS_D , isdir
consider_visiting (early): './a/c/d/e': fts_info=FTS_DP, fts_ consider_visiting (early): './a/c/d/e': fts_info=FTS_DP, fts_
consider_visiting (late): './a/c/d/e': fts_info=FTS_DP, isdir consider_visiting (late): './a/c/d/e': fts_info=FTS_DP, isdir
consider_visiting (early): './a/c/d': fts_info=FTS_DP, fts_le consider_visiting (early): './a/c/d': fts_info=FTS_DP, fts_le
consider_visiting (late): './a/c/d': fts_info=FTS_DP, isdir=1 consider_visiting (late): './a/c/d': fts_info=FTS_DP, isdir=1
consider_visiting (early): './a/c': fts_info=FTS_DP, fts_leve consider_visiting (early): './a/c': fts_info=FTS_DP, fts_leve
consider_visiting (late): './a/c': fts_info=FTS_DP, isdir=1 i consider_visiting (late): './a/c': fts_info=FTS_DP, isdir=1 i
consider_visiting (early): './a/p': fts_info=FTS_D , fts_leve consider_visiting (early): './a/p': fts_info=FTS_D , fts_leve
consider_visiting (late): './a/p': fts_info=FTS_D , isdir=1 i | consider_visiting (late): './a/p': fts_info=FTS_D , isdir=1 i
consider_visiting (early): './a/p/c': fts_info=FTS_D , fts_le | consider_visiting (early): './a/p': fts_info=FTS_DP, fts_leve
consider_visiting (late): './a/p/c': fts_info=FTS_D , isdir=1 <
consider_visiting (early): './a/p/c': fts_info=FTS_DP, fts_le <
consider_visiting (late): './a/p/c': fts_info=FTS_DP, isdir=1 <
consider_visiting (early): './a/p': fts_info=FTS_DP, fts_leve <
consider_visiting (late): './a/p': fts_info=FTS_DP, isdir=1 i consider_visiting (late): './a/p': fts_info=FTS_DP, isdir=1 i
consider_visiting (early): './a': fts_info=FTS_DP, fts_level= consider_visiting (early): './a': fts_info=FTS_DP, fts_level=
consider_visiting (late): './a': fts_info=FTS_DP, isdir=1 ign consider_visiting (late): './a': fts_info=FTS_DP, isdir=1 ign
consider_visiting (early): './c': fts_info=FTS_D , fts_level= consider_visiting (early): './c': fts_info=FTS_D , fts_level=
consider_visiting (late): './c': fts_info=FTS_D , isdir=1 ign | consider_visiting (late): './c': fts_info=FTS_D , isdir=1 ign
consider_visiting (early): './c/a': fts_info=FTS_D , fts_leve consider_visiting (early): './c/a': fts_info=FTS_D , fts_leve
consider_visiting (late): './c/a': fts_info=FTS_D , isdir=1 i | consider_visiting (late): './c/a': fts_info=FTS_D , isdir=1 i
consider_visiting (early): './c/a/c': fts_info=FTS_D , fts_le consider_visiting (early): './c/a/c': fts_info=FTS_D , fts_le
consider_visiting (late): './c/a/c': fts_info=FTS_D , isdir=1 consider_visiting (late): './c/a/c': fts_info=FTS_D , isdir=1
consider_visiting (early): './c/a/c/g': fts_info=FTS_D , fts_ consider_visiting (early): './c/a/c/g': fts_info=FTS_D , fts_
consider_visiting (late): './c/a/c/g': fts_info=FTS_D , isdir consider_visiting (late): './c/a/c/g': fts_info=FTS_D , isdir
consider_visiting (early): './c/a/c/g/f': fts_info=FTS_D , ft consider_visiting (early): './c/a/c/g/f': fts_info=FTS_D , ft
consider_visiting (late): './c/a/c/g/f': fts_info=FTS_D , isd consider_visiting (late): './c/a/c/g/f': fts_info=FTS_D , isd
consider_visiting (early): './c/a/c/g/f': fts_info=FTS_DP, ft consider_visiting (early): './c/a/c/g/f': fts_info=FTS_DP, ft
consider_visiting (late): './c/a/c/g/f': fts_info=FTS_DP, isd consider_visiting (late): './c/a/c/g/f': fts_info=FTS_DP, isd
consider_visiting (early): './c/a/c/g': fts_info=FTS_DP, fts_ consider_visiting (early): './c/a/c/g': fts_info=FTS_DP, fts_
consider_visiting (late): './c/a/c/g': fts_info=FTS_DP, isdir consider_visiting (late): './c/a/c/g': fts_info=FTS_DP, isdir
consider_visiting (early): './c/a/c': fts_info=FTS_DP, fts_le consider_visiting (early): './c/a/c': fts_info=FTS_DP, fts_le
consider_visiting (late): './c/a/c': fts_info=FTS_DP, isdir=1 consider_visiting (late): './c/a/c': fts_info=FTS_DP, isdir=1
consider_visiting (early): './c/a': fts_info=FTS_DP, fts_leve consider_visiting (early): './c/a': fts_info=FTS_DP, fts_leve
consider_visiting (late): './c/a': fts_info=FTS_DP, isdir=1 i consider_visiting (late): './c/a': fts_info=FTS_DP, isdir=1 i
consider_visiting (early): './c': fts_info=FTS_DP, fts_level= consider_visiting (early): './c': fts_info=FTS_DP, fts_level=
consider_visiting (late): './c': fts_info=FTS_DP, isdir=1 ign consider_visiting (late): './c': fts_info=FTS_DP, isdir=1 ign
consider_visiting (early): '.': fts_info=FTS_DP, fts_level= 0 consider_visiting (early): '.': fts_info=FTS_DP, fts_level= 0
consider_visiting (late): '.': fts_info=FTS_DP, isdir=1 ignor consider_visiting (late): '.': fts_info=FTS_DP, isdir=1 ignor
./c/a/c ./c/a/c
Se você notar, há uma lacuna na abordagem de Stephane que a minha não tem. Mesmo com a ameixa. Eu acho que isso mostra que seu método é evitar trabalho extra ao entrar em diretórios que, de outra forma, deveria estar ignorando.