我创建了一个目录d
和一个文件f
。然后,我只授予自己对该目录的读取权限。我知道这应该意味着我可以列出文件(例如here),但是我不能。
will@wrmpb /p/t/permissions> ls -al
total 0
drwxr-xr-x 3 will wheel 102 4 Oct 08:30 .
drwxrwxrwt 16 root wheel 544 4 Oct 08:30 ..
dr-------- 3 will wheel 102 4 Oct 08:42 d
will@wrmpb /p/t/permissions> ls d
will@wrmpb /p/t/permissions>
如果我更改了写入和执行权限,则可以看到该文件。
will@wrmpb /p/t/permissions> chmod 500 d
will@wrmpb /p/t/permissions> ls d
f
will@wrmpb /p/t/permissions>
为什么是这样?我正在使用MacOS。
编辑:参考@ccorn的答案,这与我使用鱼有关,并type ls
给出以下内容:
will@wrmpb /p/t/permissions> type ls
ls is a function with definition
function ls --description 'List contents of directory'
command ls -G $argv
end
一些准备,只是为了确保ls
不会尝试更多的事情:
$ unalias ls 2>/dev/null
$ unset -f ls
$ unset CLICOLOR
演示r
目录权限:
$ ls -ld d
dr-------- 3 ccorn ccorn 102 4 Okt 14:35 d
$ ls d
f
$ ls -l d
ls: f: Permission denied
$ ls -F d
ls: f: Permission denied
在传统的Unix文件系统中,目录只是(名称,索引节点编号)对的列表。索引节点号是一个整数,用作进入文件系统索引节点表的索引,其余文件元数据存储在该索引表中。
该r
上的目录权限允许列出它的名字,但不能访问存储在inode表,即信息,获取文件类型,文件长度,文件权限等,或打开文件。为此,您需要x
目录权限。
这就是为什么ls -l
,ls -F
,ls
用颜色编码输出等故障也不会x
允许,而只有ls
成功。
x
仅此权限就允许索引节点访问,也就是说,在该目录中给定一个明确的名称,它x
允许查找其索引节点并访问该目录条目的元数据:
$ chmod 100 d
$ ls -l d/f
-rw-r--r-- 1 ccorn ccorn 0 4 Okt 14:35 d/f
$ ls d
ls: d: Permission denied
因此,打开文件/a/b/c/f
或列出它的元数据,目录/
,/a
,/a/b
,和/a/b/c
必须被授予x
的权限。
毫不奇怪,创建目录条目需要同时具有w
和x
权限:
$ chmod 100 d
$ touch d/g
touch: d/g: Permission denied
$ chmod 200 d
$ touch d/g
touch: d/g: Permission denied
$ chmod 300 d
$ touch d/g
$
Wikipedia在有关文件系统权限的文章中对此进行了简要概述。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句