ILD

目录的权限
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2024-9-30 站点:Inside Linux Development

读权限

允许列出目录下面的文件,即允许读取目录的内容。没有读权限,ls目录会失败。

$ ls 134

ls: cannot open directory '134': Permission denied


但是可以读取目录中子文件的内容:

$ cat  134/a


写权限

允许修改目录的内容(如新建、删除子文件),没有写权限,在目录下创建文件会失败:

$ touch 134/c

touch: cannot touch '134/c': Permission denied


执行权限

允许访问目录中的文件。注意:写权限是针对目录下条目增删,而执行权限,是针对目录下的文件本身。

没有执行执行权限,则不能读、写目录下的子文件内容,也不能访问和修改子文件的属性等。


$ echo 123 > 134/a

$ chmod -x 134/

$ echo 123 > 134/a

-bash: 134/a: Permission denied


如上,之前有wx权限,所以可以新建条目(w),可以写入内容(x)。去掉x权限后,不能再修改文件内容。


没有执行权限

ls -l会失败,但是\ls会成功,前者会访问文件的属性。ls默认是alias ls='ls --color=auto',也会失败。


https://www.redhat.com/sysadmin/linux-file-permissions-explained


This permission is very different on directories compared to files. Essentially, you can think of it as providing access to the directory. Having execute permission on a directory authorizes you to look at extended information on files in the directory (using ls -l, for instance) but also allows you to change your working directory (using cd) or pass through this directory on your way to a subdirectory underneath.

Lacking execute permission on a directory can limit the other permissions in interesting ways. For example, how can you add a new file to a directory (by leveraging the write permission) if you can't access the directory's metadata to store the information for a new, additional file? You cannot. It is for this reason that directory-type files generally


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.