6

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.

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

1 Answer 1

7

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, ...).

5
  • 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. Commented Aug 14, 2015 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. Commented Aug 14, 2015 at 9:04
  • Thanks you're right I just tested your solution and it works just fine. Commented Aug 14, 2015 at 9:13
  • This worked just fine for me on Solaris 10. But I have a question: How do I skip multiple directories? Commented Nov 23, 2016 at 13:14
  • @dvai just insert extra -o -exec test {} = /otherdir \; -prune clauses before the last -o -type d one. Commented Nov 24, 2016 at 4:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.