on it road .com

例子

  1. 列出设置了其他可写和粘滞位的文件的命令。
# find / -perm -002 -and -perm -1000 -exec ls -ldb {} ;
  1. 命令列出除粘滞位设置之外的其他可写文件。
# find / -perm -002 -not -perm -1000 -exec ls -ldb {} ;
  1. 命令列出具有(组+其他)可写权限和SET UID设置的文件。
# find / -perm -4022 -exec ls -ldb {} ;
  1. 命令列出具有(组+其他)可写和SET GID设置的文件。
# find / -perm -2022 -exec ls -ldb {} ;
  1. 命令列出设置了其他可写和粘滞位的文件。
# find / -perm -1002 -exec ls -ldb {} ;
  1. 列出除粘滞位设置之外的其他可写文件的命令。
# find / -perm -002 -not -perm -1000 -exec ls -ldb {} ;

find 命令的 perm 参数

find 命令的 -perm 参数可用于查找具有特定权限的文件。
使用 -perm 参数指定权限的两种方法是:

-perm -mode    ---    All of the permission bits mode are set for the file.
-perm /mode    ---    Any of the permission bits mode are set for the file.

在烫发中,我们提到了 4 位

1st bit is for special permission e.g. SUID(4) SGID(2) or sticky bit(1)
2nd bit is for owner permission
3rd bit is for group permission
4th bit is for others permission
  1. 查找具有(组或者其他或者两者)可写权限和 SET UID 设置的文件的命令。
# find / -perm /022 -and -perm -4000 -exec ls -ldb {} ;
               ^^^^             ^
               ||||             |-- So the SUID is 4
               ||||-- Other is writable (2)  
               |||--Group permission is writable (2)
               ||-- No owner permission mentioned (0)
               |-- As the logic is OR - group or other or both

所以逻辑是:(组可写或者其他可写)AND SUID 集

  1. 命令列出除粘滞位设置之外的其他可写文件。
# find / -perm -002 -not -perm -1000 -exec ls -ldb {} ;
               ^^^^             ^
               ||||             |-- So the sticky bit is set (1)
               ||||-- Other is writable (2)        
               |||--No owner permission mentioned (0)
               ||-- No owner permission mentioned (0)
               |-- Well it does not matter if it is "-" or "/" as there is only one condition mentioned

现在这里的逻辑是:其他可写非粘性位设置

Linux/UNIX find 命令示例

find命令示例: 查找具有特定权限集的文件

有时,出于安全审计目的,可能需要查找具有特定权限的文件。
find 命令可以方便地实现这种要求。
本文说明了用于查找具有特定权限集的文件的 find 命令的几个示例。
在我们深入示例之前,这里有一些关于权限位的基础知识

4 - Read Permission (r)
2 - Write Permission (w)
1 - Executable Permission (x)

因此,如果文件具有“rwx”,它将具有 4+2+1=7 或者如果文件具有“rx”,它将具有 4+1=5

日期:2020-09-17 00:14:04 来源:oir作者:oir