Linux C学习小总结(二)- 文件与目录(文件夹)权限的区别

翻译自:http://en.wikipedia.org/wiki/File_system_permissions

Permissions(权限)


The effect of setting the permissions on a directory (rather than a file) is "one of the most frequently misunderstood file permission issues" (Hatch 2003).
对目录(文件夹)设置权限是一件极其容易引起误导的事情,问题在于在Unix系的操作系统下,文件和目录两者的“读”“写”“执行”这三个权限有不同的含义。


There are three specific permissions on Unix-like systems that apply to each class:
Unix系的操作系统有如下的三种权限:

  • 1.The read permission(读权限), which grants the ability to read a file(读取文件内容的权限). When set for a directory, this permission grants the ability to read the names of files in the directory (but not to find out any further information about them, including file type, size, ownership, permissions, etc.)

    对于目录来讲,读权限授予用户读取目录中文件的文件名(这里强调只能获取文件名)的权利,但是不能获取更多的文件信息,如文件类型,文件大小,所有者,权限等。
    ------------------------------------------------------------------------------------
  • 2.The write permission(写权限), which grants the ability to modify a file(修改文件的内容). When set for a directory, this permission grants the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files.

    对于目录来讲,写权限授予用户修改目录中条目(entries)的能力,包括创建、删除文件以及修改文件名。
    ------------------------------------------------------------------------------------
  • 3.The execute permission(执行权限), which grants the ability to execute a file. This permission must be set for executable binaries (for example, a compiled c++ program) or shell scripts (for example, a Perl program) in order to allow the operating system to run them.

    执行权限授予用户执行文件的能力,这个授权只能设置在可执行二进制文件(如编译过的C++程序)或Shell脚本(如Perl程序)以允许操作系统来运行他们。

    When set for a directory, this permission grants the ability to traverse its tree in order to access files or subdirectories, but not see files inside the directory (unless read is set).

    对于目录a来讲,执行权限授予用户“穿过,横过”(traverse)目录a本身的树(文件、目录树)以访问它下面的文件或子目录,但是不能查看它(指目录a)里面的文件,除非设置了读权限。

补充内容:(来自:《Advanced Programming in the UNIX® Environment: Second Edition》)

  • The read permission for a file determines whether we can open an existing file for reading: the O_RDONLY and O_RDWR flags for the open function.
  • The write permission for a file determines whether we can open an existing file for writing: the O_WRONLY and O_RDWR flags for the open function.
  • We must have write permission for a file to specify the O_TRUNC flag in the open function.
  • We cannot create a new file in a directory unless we have write permission and execute permission in the directory.(创建文件需要目录的写、执行权限,因为创建文件实际上为目录写入了一个目录项——文件名和i节点号)
  • To delete an existing file, we need write permission and execute permission in the directory containing the file. We do not need read permission or write permission for the file itself. (删除文件需要目录的写、执行权限,而不需要文件本身的读写权限)
  • Execute permission for a file must be on if we want to execute the file using any of the six exec functions (Section 8.10). The file also has to be a regular file.

 

posted @ 2009-12-20 21:20  Stephen.Huang  阅读(1976)  评论(0编辑  收藏  举报