33

关于文件权限的摘记

 5 years ago
source link: https://www.tuicool.com/articles/juIzEnU
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在unix中, 文件权限是一个很重要的特征, 决定了对一个文件的读, 写, 执行操作是否可以进行, 基础的相关知识就不重复说明, 在APUE中有如下摘要:

  • 对于\ 目录 \ 的读权限和执行权限的意义是不同的. 读权限允许我们读目录, 获得在该目录中所有文件名的列表. 档一个目录是我们要访问文件的路径名的一个组成部分时, 对该目录的执行权限是我们可以通过该目录(也就是搜索该目录, 寻找一个特定的文件名). 例如:

.. code:: bash

$ mkdir -p test/tmp # 创建目录
$ touch test/tmp/touchfile # touch文件
$ chmod a-x test # 去除执行权限
$ ls -l test/ # 列出test文件夹下文件
$ ls: cannot access test/tmp: Permission denied
total 0
d????????? ? ? ? ?             ? tmp
$ ls -l test/tmp # 列出下一级目录内容
ls: cannot access test/tmp: Permission denied

由于没有执行权限,执行\ ls -l test/ \ 时可以列出\ test \ 目录下的文件, 也就是能获得test目录中所有文件名的列表, 但是无法获得其他信息. 更无法通过该目录列出下一级目录的内容.

  • 对于一个文件的读权限决定了我们能否打开该文件进行读操作.
  • 对于一个文件的写权限决定了我们是否能够打开该文件进行写操作.
  • 在一个目录中创建一个新文件, 前提是必须对该目录有写和执行权限.
  • 想要删除一个现有文件, 则必须对包含该文件的目录具有写权限和执行权限.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK