What does the third character mean in "rw-" mode?

I am having a hard time understanding the manual ls

regarding the mode file rw-

. Here's a quote:

  • If r, the file is readable ; if -, this is impossible to read.

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

  • The first of the following applies:

    S If the file is not executable in owner permissions 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 the file is executable in owner permissions and set-user-ID mode is set. If in group permissions the file is executable and setgroup-ID mode is set.

    x The file is executable or the directory is searchable.

    - File not readable , writable, executable, not user id, and set-group-ID or sticky mode.

In particular, the two sections in bold seem to contradict each other: according to the first, because the mode starts with r

, the file is readable, but according to the latter, the file is not . But this is obviously not the case.

So what does the third section mean about "unreadable, writeable ..." file?

+3


source to share


2 answers


Your page is ls

not standard. the standard POSIX man page for ls does not . Here's a relevant passage:

Each field must contain three characters:

  • If "r", the file is readable; if '-', the file cannot be read.

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

  • The first of the following applies:

    S

    •       If in <owner permissions>, the file is not executable and the 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 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 delete flag is set.

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

x

  •       The file is executable or the directory is searchable.

-

  •       None of the "S", "s", "T", "t", or "x" attributes apply.

Which I think makes sense.



The type is not represented in the permission bits - you are only looking at those reports ls(1)

, not how they are stored. Traditionally, mode and type have used 32-bit together, but this depends on the filesystem and many are now 64-bit. Permissions are only 9 bits per inode.

See man 2 stat

and search st_mode

. This is a low level C routine that probably uses ls(1)

. On some platforms, it is also available as a command line man 1 stat

.

+2


source


Each numbered dot in your quote applies in turn to each of the three characters.

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 specified property

If the character is "-", then the file does not have this property.



The first three characters (after the directory ID) apply to user permissions, permissions from three to groups , and the third applies to everyone else.

0


source







All Articles