I'm trying to exclude the directory /zones in my find command. I don't have GNU find available, just the native Solaris find.

I tried something like this:

find / -type d ! -name zones

The problem is that with this exclude I also lose sub-directories like /etc/zones.

Is there a way to specify the complete directory name like:

find / -type d ! -name ^\/zones

I already tested lots of approaches but I can't include the / in front of the string.

  • does solaris find support asterisks? like find / ! -name '*zones' ? – Fiximan Aug 14 '15 at 8:43
  • maybe this post will help – gwillie Aug 14 '15 at 8:45
  • Yes asteriks are supported but with an exclude on *zones I will end up with the same issue as before... – Nenzo Aug 14 '15 at 8:55

Here is a portable way:

find / -type d -exec test {} = /zones \; -prune -o -type d -print

Note that GNU find might be available on an alternate directory depending on the Solaris release you are using (like /usr/sfw/bin/gfind, /usr/gnu/bin/find, ...).

| improve this answer | |
  • This approach will probably work but search the /zones directory anyway which can result in very high execution times. It would be best to not search this directory in the first place. – Nenzo Aug 14 '15 at 8:58
  • @Nenzo I used -prune which is documented as -prune Always yields true. Does not examine any directories or files in the directory structure below the pattern just matched. – jlliagre Aug 14 '15 at 9:04
  • Thanks you're right I just tested your solution and it works just fine. – Nenzo Aug 14 '15 at 9:13
  • This worked just fine for me on Solaris 10. But I have a question: How do I skip multiple directories? – dvai Nov 23 '16 at 13:14
  • @dvai just insert extra -o -exec test {} = /otherdir \; -prune clauses before the last -o -type d one. – jlliagre Nov 24 '16 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.