Find directories and files with permissions other than 775 / 664

Use the -perm test to find in combination with -not:

find -type d -not -perm 775 -o -type f -not -perm 664
  • -perm 775 matches all files with permissions exactly equal to 775. -perm 664 does the same for 664.
  • -not (boolean NOT) negates the test that follows, so it matches exactly the opposite of what it would have: in this case, all those files that don't have the correct permissions.
  • -o (boolean OR) combines two sets of tests together, matching when either of them do: it has the lowest precedence, so it divides our tests into two distinct groups. You can also use parentheses to be more explicit. Here we match directories with permissions that are not 775 and ordinary files with permissions that are not 664.

If you wanted two separate commands for directories and files, just cut it in half at -o and use each half separately:

find -type f -not -perm 664
find -type d -not -perm 775

I have no idea what your code was trying to achieve. Normally the reason for finding Files and Directories with incorrect permissions is for the purpose of changing them.

So this is what I am successfully using in Ubuntu 16.04

find \! -perm 775 -type d -exec chmod 775 {} \;
find \! -perm 664 -type f -exec chmod 664 {} \;

This demonstrates the ! symbol being escaped