Linux 如何找到只有所有者具有特定权限的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15247563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:12:26  来源:igfitidea点击:

How can I find files that only have certain permission for owner?

linuxbashfilepermissionsfind

提问by Alex Gao

I would like to find files only by a certain user's permission. For example, if I want to find a file that I have full permission.

我只想通过特定用户的权限查找文件。例如,如果我想查找我拥有完全权限的文件。

I may do something like:

我可能会这样做:

find . -user $(whoami) -perm 

But what should I put after -permif I want to ignore the permission of root and other users.

但是-perm如果我想忽略 root 和其他用户的权限,我应该放什么。

采纳答案by jim mcnamara

Start with:

从...开始:

find /path/to/file -user user1 -perm -u+rwx

This means: look for files starting in /path/to/files, owned by user1, where the permissions for group and other can be anything (-in front of the permission string) and the users permissions are only: rwx

这意味着:查找以 开头/path/to/files、由 拥有的文件user1,其中 group 和 other 的权限可以是任何内容(-在权限字符串前面),并且用户权限仅为:rwx

To search for files only (no directories) then add -type f.

要仅搜索文件(无目录),请添加-type f.

Also, try some reading. This has great examples: Find tutorial

另外,尝试一些阅读。这有很好的例子:查找教程

回答by simhumileco

-perm -mode

All of the permission bits mode are set for the file. Symbolic modes are accepted in this form, and this is usually the way in which would want to use them. You must specify 'u', 'g' or 'o' if you use a symbolic mode.

-烫发模式

为文件设置了所有权限位模式。符号模式以这种形式被接受,这通常是使用它们的方式。如果使用符号模式,则必须指定 'u'、'g' 或 'o'。

find . -user $(whoami) -perm -007

for the specified user, it returns files with the following privileges: rwx,

对于指定的用户,它返回具有以下权限的文件:rwx

find . -user $(whoami) -perm -006

for the specified user, it returns files with the following privileges: rwx, rw,

对于指定的用户,它返回具有以下权限的文件:rwxrw

find . -user $(whoami) -perm -005

for the specified user, it returns files with the following privileges: rwx, rx,

对于指定的用户,它返回具有以下权限的文件:rwxrx

find . -user $(whoami) -perm -004

for the specified user, it returns files with the following privileges: rwx, rw, rx, r,

对于指定的用户,它返回具有以下权限的文件:rwxrwrxr

find . -user $(whoami) -perm -003

for the specified user, it returns files with the following privileges: rwx, wx,

对于指定的用户,它返回具有以下权限的文件:rwxwx

find . -user $(whoami) -perm -002

for the specified user, it returns files with the following privileges: rwx, rw, wx, w,

对于指定的用户,它返回具有以下权限的文件:rwx, rw, wx, w,

find . -user $(whoami) -perm -001

for the specified user, it returns files with the following privileges: rwx, rx, wx, x,

对于指定的用户,它返回具有以下权限的文件:rwxrxwxx

find . -user $(whoami) -perm -000

for the specified user, it returns files with the following privileges: rwx, rw, rx, wx, r, w, x, 0,

对于指定的用户,它返回具有以下权限的文件:rwx, rw, rx, wx, r, w, x, 0,

-perm /mode

Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify 'u', 'g' or 'o' if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test matches any file (the idea here is to be consistent with the behaviour of -perm -000).

-烫发/模式

为文件设置了任何权限位模式。这种形式接受符号模式。如果使用符号模式,则必须指定 'u'、'g' 或 'o'。有关一些说明性示例,请参阅示例部分。如果 mode 中没有设置权限位,则此测试匹配任何文件(这里的想法是与 -perm -000 的行为保持一致)。

find . -user $(whoami) -perm /007

for the specified user, it returns files with the following privileges: rwx, rw, rx, wx, r, w, x,

对于指定的用户,它返回具有以下权限的文件:rwxrwrxwxrwx

find . -user $(whoami) -perm /006

for the specified user, it returns files with the following privileges: rwx, rw, rx, wx, r, w,

对于指定的用户,它返回具有以下权限的文件:rwxrwrxwxrw

find . -user $(whoami) -perm /005

for the specified user, it returns files with the following privileges: rwx, rw, rx, wx, r, x,

对于指定的用户,它返回具有以下权限的文件:rwxrwrxwxrx

find . -user $(whoami) -perm /004

for the specified user, it returns files with the following privileges: rwx, rw, rx, r,

对于指定的用户,它返回具有以下权限的文件:rwxrwrxr

find . -user $(whoami) -perm /003

for the specified user, it returns files with the following privileges: rwx, rw, rx, wx, w, x,

对于指定的用户,它返回具有以下权限的文件:rwxrwrxwxwx

find . -user $(whoami) -perm /002

for the specified user, it returns files with the following privileges: rwx, rw, wx, w,

对于指定的用户,它返回具有以下权限的文件:rwx, rw, wx, w,

find . -user $(whoami) -perm /001

for the specified user, it returns files with the following privileges: rwx, rx, wx, x,

对于指定的用户,它返回具有以下权限的文件:rwxrxwxx

find . -user $(whoami) -perm /000

for the specified user, it returns files with the following privileges: rwx, rx, rw, wx, r, w, x, 0.

对于指定的用户,它返回具有以下权限的文件:rwxrxrwwxrwx0

Examples have been tested.

示例已经过测试。

Source of citations.

引文来源。