0

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
...
user3313834
  • 7,327
  • 12
  • 56
  • 99

1 Answers1

2

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
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • 1
    Or in other words, your attempt was really doing basically `-type d -o print`. You could fix that by moving the parentheses, too. – tripleee Sep 01 '19 at 14:41
  • @tripleee can you give the full invocation? I couldn't make it work without nested parens `find -type d ! \( \( -path './2018*' -o -path './S*' \) -prune \)` – oguz ismail Sep 01 '19 at 14:51
  • With that variation, you don't need the `-prune`, do you? – tripleee Sep 01 '19 at 14:53
  • You actually need. Without -prune it would recurse into dirs matching ./2018* and ./S*. It wouldn't print anything in them but it'd recurse. Try creating gazillions of directories in 2018 and compare with and without prune – oguz ismail Sep 01 '19 at 14:54
  • 1
    Unfortunately, not in a place where I can test. Let me get back to you tomorrow. – tripleee Sep 01 '19 at 15:25
  • `find . \( -path './2018*' -o -path './S*' \) -o -type d -print` seems to do what I expect. – tripleee Sep 02 '19 at 10:02