- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 211字
- 2021-07-09 19:46:14
Matching based on file permissions and ownership
It is possible to match files based on the file permissions. We can list out the files with specified file permissions:
$ find . -type f -perm 644 -print # Print files having permission 644
The -perm option specifies that find should only match files with their permission set to a particular value. Permissions are explained in more detail in the Working with file permissions, ownership, and the sticky bit recipe in Chapter 3, File In, File Out.
As an example usage case, we can consider the case of the Apache web server. The PHP files in the web server require proper permissions to execute. We can find PHP files that don't have proper executing permissions:
$ find . -type f -name "*.php" ! -perm 644 -print PHP/custom.php $ ls -l PHP/custom.php -rw-rw-rw-. root root 513 Mar 13 2016 PHP/custom.php
We can also search files based on ownership. The files owned by a specific user can be found with the -user USER option.
The USER argument can be a username or UID.
For example, to print a list of all files owned by the slynux user, you can use the following command:
$ find . -type f -user slynux -print