Article sections

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

    find -type d -not -perm 755 -o -type f -not -perm 644
    
    • -perm 755 matches all files with permissions exactly equal to 755. -perm 644 does the same for 644.
    • -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 755 and ordinary files with permissions that are not 644.

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

    Find file permission not equal to 644

    find -type f -not -perm 644

    Find Directory permission not equal to 755

    find -type d -not -perm 755

    Change file permission to 644 including files in current as well as subdirectories

    find -type f -not -perm 644 -print0 | xargs -0 chmod 0644

    Change Directory permission to 755 including directories in current as well as subdirectories subdirectories

    find -type d -not -perm 755 -print0 | xargs -0 chmod 755

    in cPanel & WHM Server