"rw-" 文件模式中的第三个符号是什么意思?

What does third symbol in "rw-" file mode mean?

我无法理解 ls 关于具有 rw- 模式的文件的手册。这是引用:

  1. If r, the file is readable; if -, it is not readable.

  2. If w, the file is writable; if -, it is not writable.

  3. The first of the following that applies:

    S If in the owner permissions, the file is not executable and set-user-ID mode is set. If in the group permissions, the file is not executable and set-group-ID mode is set.

    s If in the owner permissions, the file is executable and set-user-ID mode is set. If in the group permissions, the file is executable and setgroup-ID mode is set.

    x The file is executable or the directory is searchable.

    - The file is neither readable, writable, executable, nor set-user-ID nor set-group-ID mode, nor sticky.

特别是,粗体部分似乎相互矛盾:根据第一个,由于模式以 r 开头,文件是可读的,但根据最后一个,文件不可读。但是,显然,事实并非如此。

那么,第三部分关于文件 "neither readable, writable..." 是什么意思?

您引用中的每个编号点依次适用于三个字符中的每一个。

If the first character is 'r', the file is readable

If the second character is 'w', the file is writable

If the third character is 'x/s/S', the file has the listed property

If the character is '-', then the file does not have that property.

前三个字符(在目录标识符之后)适用于 user 权限,后三个适用于 group 权限,第三个给其他人。

您的 ls 手册页不符合标准。 POSIX standard man page for ls 而不是 那样表述。以下是相关摘录:

Each field shall have three character positions:

  1. If 'r' , the file is readable; if '-' , the file is not readable.

  2. If 'w' , the file is writable; if '-' , the file is not writable.

  3. The first of the following that applies:

    S

      If in <owner permissions>, the file is not executable and set-user-ID mode is set. If in <group permissions>, the file is not executable and set-group-ID mode is set.

    s

      If in <owner permissions>, the file is executable and set-user-ID mode is set. If in <group permissions>, the file is executable and set-group-ID mode is set.

    T

      If in <other permissions> and the file is a directory, search permission is not granted to others, and the restricted deletion flag is set.

    t

      If in <other permissions> and the file is a directory, search permission is granted to others, and the restricted deletion flag is set.

    x

      The file is executable or the directory is searchable.

    -

      None of the attributes of 'S' , 's' , 'T' , 't' , or 'x' applies.

我认为这更有意义。

类型未在权限位中表示 - 您只查看 ls(1) 报告的内容,而不是它的存储方式。传统上,模式和类型一起使用 32 位,但这取决于文件系统,现在很多文件系统都是 64 位的。权限在 inode 中只有 9 位。

查看 man 2 stat 并搜索 st_models(1) 可能使用的是低级 C 例程。在某些平台上,它也可以作为命令行程序使用 man 1 stat.