0

I need to search for all files that have certain permissions while excluding two directories under /. These directories contain far to much information and the system chokes on them.

I've tried various combinations of -type -path -wholename and -prune and cannot seem to get it to exclude these two directories.

Currently this is what I am attempting.

find . -path './dir1/' -prune -o -path './dir2/' -prune -o -type d -perm -002 ! -perm -1000 > wwlist

Any assistance would be greatly appreciated.

konsolebox
  • 60,986
  • 9
  • 83
  • 94
SeaMcB27
  • 1
  • 1
  • This question belongs on https://superuser.com/ or https://unix.stackexchange.com/. – ajp15243 Aug 01 '14 at 13:57
  • Meant to add a comment as well as just closing this. But in particular, your syntax would be something like `find \( -path './dir1' -o -path './dir2' \) -type d -prune -o -type -d -perm -002 ! -perm -1000 -print > wwlist`. Which would get treated logically as `find ((-path './dir1' -o -path './dir2)) AND -type d AND -prune) OR (-type -d AND -perm -002 AND (! -perm -1000) AND -print)` . Also not positive, but I believe that find won't treat `-path './dir1'` and `-path './dir1/'` the same, and I think the first will match the path at that point. – Reinstate Monica Please Aug 02 '14 at 04:14

1 Answers1

0

You can add conditions that would exclude directories:

find . '!' -path './dir1/*' '!' -path './dir2/*' ...

To be more precise also exclude the directory themselves:

find . '!' -path './dir1' '!' -path './dir2' '!' -path './dir1/*' '!' -path './dir2/*' ...

You can also use regex:

find . -regextype posix-extended -not -regex '[.]/dir(1|2)(/.*)?' ...
  • You can also use -not instead of ! but it's not POSIX compliant.
  • -wholename is synonymous to -path but it's not POSIX compliant.
konsolebox
  • 60,986
  • 9
  • 83
  • 94