【问题标题】:List the files that I can read列出我可以阅读的文件
【发布时间】:2018-05-27 19:56:01
【问题描述】:

我想列出当前用户可以在 bash 中读取的所有文件。 我不确定检查它的最佳方法是什么。我正在考虑类似于ls -l | grep <myusername>|<mygroupname>find . 的内容,但这不涉及其他权限。

另外,我正在开发 NetBSD 机器。

【问题讨论】:

  • find . -readable 是否存在于 NetBSD 中?
  • @Ingaz 没有可读标志。所有 bsd 标志都是单个字符。没有更多的选择。
  • openbsd 和 netbsd 似乎使用相同的 find,它支持 -perm 标志,您可以在八进制中提供所需的权限模式:https://man.openbsd.org/find#-perm
  • 嗯。 Looks like find . -perm /+r 必须可用。不确定perm的格式

标签: bash unix permissions


【解决方案1】:

考虑以下两个文件,其中一个可以被用户读取,而另一个不能:

[fsilveir@fsilveir tmp]$ ls -l ./test_dir/can_read.txt ./test_dir/cant_read.txt
-rw-r--r--. 1 root root 861784 May 29 20:34 ./test_dir/can_read.txt
-rwx------. 1 root root      0 May 29 20:30 ./test_dir/cant_read.txt

您可以将find-perm 选项一起使用。使用+r可以列出可以阅读的文件,使用-r可以找到无法阅读的文件,如下图:

[fsilveir@fsilveir tmp]$ find . -name "*.txt" -perm -g+r 2>/dev/null
./test_dir/can_read.txt
[fsilveir@fsilveir tmp]$ 

另一种方法是使用find-readable 选项,如下所示:

[fsilveir@fsilveir tmp]$ find . -name "*.txt" -readable
./test_dir/can_read.txt

[fsilveir@fsilveir tmp]$ find . -name "*.txt" ! -readable
./test_dir/cant_read.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    相关资源
    最近更新 更多