find can look for files with specific permissions. It uses an octal number for these permissions. If you aren't comfortable with octal numbers and the way Unix uses them in file permissions, Section 1.17 is good background reading.
The string rw-rw-r-- indicates that you and members of your group have read and write permission, while the world has read-only privilege. The same permissions are expressed as an octal number as 664. To find all *.o files with these permissions, use the following:
% find . -name \*.o -perm 664 -print
To see if you have any directories with write permission for everyone, use this:
% find . -type d -perm 777 -print
The previous examples only match an exact combination of permissions. If you wanted to find all directories with group write permission, you want to match the pattern ----w----. There are several combinations that can match. You could list each combination, but find allows you to specify a pattern that can be bitwise ANDed with the permissions of the file. Simply put a minus sign (-) before the octal value. The group write permission bit is octal 20, so the following negative value:
% find . -perm -20 -print
will match the following common permissions:
Permission |
Octal value |
---|---|
rwxrwxrwx |
777 |
rwxrwxr-x |
775 |
rw-rw-rw- |
666 |
rw-rw-r-- |
664 |
rw-rw---- |
660 |
If you wanted to look for files that the owner can execute (i.e., shell scripts or programs), you want to match the pattern --x------ by typing:
% find . -perm -100 -print
When the -perm argument has a minus sign, all of the permission bits are examined, including the set user ID, set group ID, and sticky bits.
-- BB
Copyright © 2003 O'Reilly & Associates. All rights reserved.