If the file structure is like this:/a/p/c/d.../c/a/c/g/f/.../a/c/d/e/......And I want to do this: find -mindepth 3 -type d -name p -prune -or -name c -printHowever, this command will not prune the 'p' directory and the first line will included. I know it's actually not a conflict. But how to prune 'p' with the mindepth applied?
The find command: the options '-mindepth' conflicts with the action '-prune'
find
I think I would do it this way:find -mindepth 3 -type d ! -path '*/p/*' -name c -printBased on @StephaneChazelas' feedback I believe this method would eliminate the extraneous searching into any /p/ directories:find -mindepth 3 -type d -path '*/p/*' -prune -o -name c -printAnalyzing a findTo compare find commands you can add the debug switch -D search so that you can see how a particular find would perform vs. another.I ran @StephaneChazelas' command vs. mine to see where the differences were. The 2 commands are run and their output is run into an sdiff below:$ 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= 0consider_visiting (late): `.': fts_info=FTS_D , isdir=1 ignor | consider_visiting (late): `.': fts_info=FTS_D , isdir=1 ignorconsider_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 ignconsider_visiting (early): `./a/c': fts_info=FTS_D , fts_leve   consider_visiting (early): `./a/c': fts_info=FTS_D , fts_leveconsider_visiting (late): `./a/c': fts_info=FTS_D , isdir=1 i | consider_visiting (late): `./a/c': fts_info=FTS_D , isdir=1 iconsider_visiting (early): `./a/c/d': fts_info=FTS_D , fts_le   consider_visiting (early): `./a/c/d': fts_info=FTS_D , fts_leconsider_visiting (late): `./a/c/d': fts_info=FTS_D , isdir=1   consider_visiting (late): `./a/c/d': fts_info=FTS_D , isdir=1consider_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 , isdirconsider_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, isdirconsider_visiting (early): `./a/c/d': fts_info=FTS_DP, fts_le   consider_visiting (early): `./a/c/d': fts_info=FTS_DP, fts_leconsider_visiting (late): `./a/c/d': fts_info=FTS_DP, isdir=1   consider_visiting (late): `./a/c/d': fts_info=FTS_DP, isdir=1consider_visiting (early): `./a/c': fts_info=FTS_DP, fts_leve   consider_visiting (early): `./a/c': fts_info=FTS_DP, fts_leveconsider_visiting (late): `./a/c': fts_info=FTS_DP, isdir=1 i   consider_visiting (late): `./a/c': fts_info=FTS_DP, isdir=1 iconsider_visiting (early): `./a/p': fts_info=FTS_D , fts_leve   consider_visiting (early): `./a/p': fts_info=FTS_D , fts_leveconsider_visiting (late): `./a/p': fts_info=FTS_D , isdir=1 i | consider_visiting (late): `./a/p': fts_info=FTS_D , isdir=1 iconsider_visiting (early): `./a/p/c': fts_info=FTS_D , fts_le | consider_visiting (early): `./a/p': fts_info=FTS_DP, fts_leveconsider_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 iconsider_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 ignconsider_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 ignconsider_visiting (early): `./c/a': fts_info=FTS_D , fts_leve   consider_visiting (early): `./c/a': fts_info=FTS_D , fts_leveconsider_visiting (late): `./c/a': fts_info=FTS_D , isdir=1 i | consider_visiting (late): `./c/a': fts_info=FTS_D , isdir=1 iconsider_visiting (early): `./c/a/c': fts_info=FTS_D , fts_le   consider_visiting (early): `./c/a/c': fts_info=FTS_D , fts_leconsider_visiting (late): `./c/a/c': fts_info=FTS_D , isdir=1   consider_visiting (late): `./c/a/c': fts_info=FTS_D , isdir=1consider_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 , isdirconsider_visiting (early): `./c/a/c/g/f': fts_info=FTS_D , ft   consider_visiting (early): `./c/a/c/g/f': fts_info=FTS_D , ftconsider_visiting (late): `./c/a/c/g/f': fts_info=FTS_D , isd   consider_visiting (late): `./c/a/c/g/f': fts_info=FTS_D , isdconsider_visiting (early): `./c/a/c/g/f': fts_info=FTS_DP, ft   consider_visiting (early): `./c/a/c/g/f': fts_info=FTS_DP, ftconsider_visiting (late): `./c/a/c/g/f': fts_info=FTS_DP, isd   consider_visiting (late): `./c/a/c/g/f': fts_info=FTS_DP, isdconsider_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, isdirconsider_visiting (early): `./c/a/c': fts_info=FTS_DP, fts_le   consider_visiting (early): `./c/a/c': fts_info=FTS_DP, fts_leconsider_visiting (late): `./c/a/c': fts_info=FTS_DP, isdir=1   consider_visiting (late): `./c/a/c': fts_info=FTS_DP, isdir=1consider_visiting (early): `./c/a': fts_info=FTS_DP, fts_leve   consider_visiting (early): `./c/a': fts_info=FTS_DP, fts_leveconsider_visiting (late): `./c/a': fts_info=FTS_DP, isdir=1 i   consider_visiting (late): `./c/a': fts_info=FTS_DP, isdir=1 iconsider_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 ignconsider_visiting (early): `.': fts_info=FTS_DP, fts_level= 0   consider_visiting (early): `.': fts_info=FTS_DP, fts_level= 0consider_visiting (late): `.': fts_info=FTS_DP, isdir=1 ignor   consider_visiting (late): `.': fts_info=FTS_DP, isdir=1 ignor./c/a/c                             ./c/a/cIf you notice, there's a gap in Stephane's approach that mine doesn't have. Even with the prune. I think this shows that his method is avoiding extra work in walking into directories that it should otherwise be ignoring.