【发布时间】:2016-12-15 07:28:20
【问题描述】:
我正在练习 unix find 命令和基于权限的过滤。这是我练习目录上的ls -al 的样子:
[tom@t-degroot1 ~]$ ls -al
total 44
drwx------. 8 tom tom 4096 Dec 13 09:08 .
drwxr-xr-x. 7 root root 63 Nov 5 16:38 ..
-rw-------. 1 tom tom 9547 Dec 15 08:16 .bash_history
-rw-r--r--. 1 tom tom 18 Oct 26 00:36 .bash_logout
-rw-r--r--. 1 tom tom 193 Oct 26 00:36 .bash_profile
-rw-r--r--. 1 tom tom 231 Oct 26 00:36 .bashrc
drwxrwxr-x. 2 tom tom 21 Dec 12 22:14 chattrdir
-rw-rw-r--. 1 tom tom 0 Dec 13 09:03 file1
-rw-rw-r--. 1 tom tom 0 Dec 13 09:03 file2
drwxr-xr-x. 2 tom tom 4096 Dec 11 14:36 fileext
-rw-------. 1 tom tom 164 Dec 14 09:25 .lesshst
drwxr-xr-x. 4 tom tom 37 Dec 20 2015 .mozilla
drwxrw----. 3 tom tom 18 Dec 8 20:20 .pki
drwx------. 2 tom tom 24 Nov 7 09:51 .ssh
-rw-------. 1 tom tom 3639 Dec 8 20:56 .viminfo
drwxrwxr-x. 2 tom tom 4096 Dec 8 21:26 wildcard
我使用 find 命令根据权限进行搜索:
[tom@t-degroot1 ~]$ find . -maxdepth 1 -perm /004
./.bash_logout
./.bash_profile
./.bashrc
./.mozilla
./chattrdir
./file1
./file2
./fileext
./wildcard
接下来看看这些是否确实是为“其他”设置了读取权限位的唯一文件,我将输出通过管道传输到ls:
[tom@t-degroot1 ~]$ find . -maxdepth 1 -perm /o+r | ls -al
total 44
drwx------. 8 tom tom 4096 Dec 13 09:08 .
drwxr-xr-x. 7 root root 63 Nov 5 16:38 ..
-rw-------. 1 tom tom 9584 Dec 15 08:23 .bash_history
-rw-r--r--. 1 tom tom 18 Oct 26 00:36 .bash_logout
-rw-r--r--. 1 tom tom 193 Oct 26 00:36 .bash_profile
-rw-r--r--. 1 tom tom 231 Oct 26 00:36 .bashrc
drwxrwxr-x. 2 tom tom 21 Dec 12 22:14 chattrdir
-rw-rw-r--. 1 tom tom 0 Dec 13 09:03 file1
-rw-rw-r--. 1 tom tom 0 Dec 13 09:03 file2
drwxr-xr-x. 2 tom tom 4096 Dec 11 14:36 fileext
-rw-------. 1 tom tom 164 Dec 14 09:25 .lesshst
drwxr-xr-x. 4 tom tom 37 Dec 20 2015 .mozilla
drwxrw----. 3 tom tom 18 Dec 8 20:20 .pki
drwx------. 2 tom tom 24 Nov 7 09:51 .ssh
-rw-------. 1 tom tom 3639 Dec 8 20:56 .viminfo
drwxrwxr-x. 2 tom tom 4096 Dec 8 21:26 wildcard
您看到以下文件确实没有为其他人设置了读取权限,即使我只想要为其他人设置了读取权限位的文件:
-rw-------. 1 tom tom 9584 Dec 15 08:23 .bash_history
rw-------. 1 tom tom 164 Dec 14 09:25 .lesshst
drwxrw----. 3 tom tom 18 Dec 8 20:20 .pki
drwx------. 2 tom tom 24 Nov 7 09:51 .ssh
-rw-------. 1 tom tom 3639 Dec 8 20:56 .viminfo
这些文件怎么可能出现在输出中?我只将根据我的查找搜索可读的文件传送到ls 命令,ls 显示它们不可读。
【问题讨论】: