bashgnu-findutils

in find, `-type d` get files an not only directories if used with `-prune`


I use this:

$ find . -type d \( -path './2018*' -o -path "./S*" \) -prune\
         -o -print

to get all directories (-type d) excluding 2018, S1 and S2

The exclusion of directories work but I get plenty of files:

...
./git_wc
./budget
./budget/mail_0625
./budget/mail_0625/prez.pptx
./budget/budget_v2.xlsx
./budget/achats
./budget/achats/106-1396140_V1_20190731.pdf
./rh
./rh/file.docx

BTW I look for a pure find answer, I know how to do this with tree:

$ tree -d -L 2 -I 'S1|2018' -fi
...
./git_wc
./budget
./budget/mail_0625
./budget/achats
./rh
...

Solution

  • Your command's logic is "prune all directories that have names matching the glob ./2018* or ./S*; print everything else". You want:

     find . \( -path './2018*' -o -path "./S*" \) -prune\
             -o -type d -print