如何搜索具有特定权限的文件。例如,我有 10000 个文件,我想找到那些具有 READ ONLY 标志的文件。在另一种情况下,我想搜索具有特定所有者的另一个。或者在另一个中查看只读和可执行的文件。
小智 10
使用该find
命令可能最简单,它允许您递归搜索目录树。例如,如果您特别想查找只读文件,您可以键入
find <specify location> -type f -perm -444
Run Code Online (Sandbox Code Playgroud)
对于属于特定用户的文件,您可以使用
find <location> -type f -user mike
Run Code Online (Sandbox Code Playgroud)
对于可执行文件(对于所有人),您可以使用
find <location> -type f -perm -777
Run Code Online (Sandbox Code Playgroud)
对于所有可执行文件和只读文件,您将使用 555 代替上面示例中的 777。您还可以通过替换-user mike
来搜索属于某个组的文件-group mike
。
要否定搜索词并搜索完全相反的词,您可以使用这样的感叹号:
find <location> -type f ! -perm -444
Run Code Online (Sandbox Code Playgroud)
注意:在权限前指定破折号(例如-perm -444
)意味着将找到所有具有只读标志的文件,而不仅仅是那些是 444 的文件;要准确搜索 444,只需删除破折号(例如-perm 444
)。
注 2:也可以使用-a
for 和-o
for or来寻求权限的组合;例如,要准确查找这些权限,请键入:
find <location> -type f -perm 744 -o -perm 666
Run Code Online (Sandbox Code Playgroud)
可以使用 搜索目录-type d
。
查看man find
其他可用的排列。
归档时间: |
|
查看次数: |
5617 次 |
最近记录: |