简体   繁体   English

列出我可以阅读的文件

[英]List the files that I can read

I would like to list any files that can be read by my current user in bash. 我想在bash中列出当前用户可以读取的所有文件。 I'm not sure what would be the best way to check for that. 我不确定什么是最好的检查方法。 I'm thinking something along the lines of ls -l | grep <myusername>|<mygroupname> 我在ls -l | grep <myusername>|<mygroupname>东西ls -l | grep <myusername>|<mygroupname> ls -l | grep <myusername>|<mygroupname> or find . ls -l | grep <myusername>|<mygroupname>find . , but that doesn't deal with the other permissions. ,但不会处理其他权限。

Also, I'm working on NetBSD box. 另外,我正在使用NetBSD盒。

Considering the 2 files below, where one can be read by user, and the other can't: 考虑以下2个文件,其中一个可以由用户读取,而另一个则不能:

[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

You can use find with -perm option. 您可以将find-perm选项一起使用。 By using +r you'll list the files you can read, and using -r for finding the ones you can't read, as shown below: 通过使用+r您将列出您可以阅读的文件,并使用-r查找您无法阅读的文件,如下所示:

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

Another approach is using find with -readable option, as shown below: 另一种方法是使用带有- -readable选项的find ,如下所示:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM