home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 17.14 Searching for Files by Size Chapter 17
Finding Files with find
Next: 17.16 Searching by Owner and Group
 

17.15 Searching for Files by Permission

[If you aren't comfortable with octal numbers and the way UNIX uses them in file permissions, article 1.23 in is good background reading. -JP]

find can look for files with specific permissions. It uses an octal number for these permissions. 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 the above permissions, use:

% 

find . -name \*.o -perm 664 -print

To see if you have any directories with write permission for everyone, use:

% 

find . -type d -perm 777 -print

The examples above 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 bit-wise 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 you 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 bits ( 1.23 ) .

- BB


Previous: 17.14 Searching for Files by Size UNIX Power Tools Next: 17.16 Searching by Owner and Group
17.14 Searching for Files by Size Book Index 17.16 Searching by Owner and Group

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru