113

When I ls -la, it prints many attributes. Something like this:

-rwSrwSr-- 1 www-data www-data   45 2012-01-04 05:17 README

Shamefully, I have to confess I don't know the exact meaning of each attributes. For example, what's the meaning of big S in the string -rwSrwSr--? What's the following 1? I know others roughly.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Eonil
  • 4,657
  • 40
    Eonil: There's nothing shameful about needing to ask a question, after all that's what this site is about. And as for those who say RTFM, many of us DO THAT and still cannot find the simplest answer after wading through pages of hard-to-read programmer-written documentation (and I'm a programmer). In some cases, we're on systems where the man pages were not installed. For all those reasons, and many more, sites like this are a godsend. Thanks for asking the same question I had. – Alan Aug 10 '12 at 22:10
  • 4
    Great question - very specific along with a concrete example. – Ole Apr 16 '16 at 20:06

5 Answers5

92

The documentation of the ls command answers these questions. On most unix variants, look up the ls man page (man ls or online). On Linux, look up the Info documentation (info ls) or online.

The letter s denotes that the setuid (or setgid, depending on the column) bit is set. When an executable is setuid, it runs as the user who owns the executable file instead of the user who invoked the program. The letter s replaces the letter x. It's possible for a file to be setuid but not executable; this is denoted by S, where the capital S alerts you that this setting is probably wrong because the setuid bit is (almost always) useless if the file is not executable.

When a directory has setuid (or setgid) permissions, any files created in that directory will be owned by the user (or group) matching the owner (or group) of the directory.

The number after the permissions is the hard link count. A hard link is a path to a file (a name, in other words). Most files have a single path, but you can make more with the ln command. (This is different from symbolic links: a symbolic link says “oh, actually, this file is elsewhere, go to <location>”.) Directories have N+2 hard links where N is the number of subdirectories, because they can be accessed from their parent, from themselves (through the . entry), and from each subdirectory (through the .. entry).

qneill
  • 113
  • 6
    What does it mean on OS X when its applied to a directory? For example, $ ls /Users returns drws--S---+ 12 jdoe staff 408 Jul 9 2013 jdoe –  Aug 26 '15 at 12:07
  • 5
    @jww It means that files created in that directory will belong to the group that owns the directory, but that's the default on OSX anyway. See https://en.wikipedia.org/wiki/Setuid#setuid_and_setgid_on_directories and http://unix.stackexchange.com/questions/12842/make-all-new-files-in-a-directory-accessible-to-a-group/12845#comment17274_12845 – Gilles 'SO- stop being evil' Aug 26 '15 at 12:26
  • @Gilles, When you said that a file is not "executable" ? Does it mean it does not have the executable privilege or that it is not a file type which can be executed ? – ransh Aug 28 '17 at 09:13
  • @ransh I mean the execute (x) permission. – Gilles 'SO- stop being evil' Aug 28 '17 at 11:46
  • I've submitted an edit similar to the point made in @Jag's answer below – qneill Jun 28 '18 at 15:40
  • 1
    If a directory is capital S, not lowercase s, does that also mean the setting is probably wrong or does this only apply to files? – notbrain Jan 24 '19 at 18:56
  • 3
    @Brian Yes. On a directory, the setgid bit causes newly created files to belong to the group that owns the directory. If the group can't access files in the directory, I don't see the point. – Gilles 'SO- stop being evil' Jan 24 '19 at 22:52
  • info ls very frustrating that this is missing from man – akostadinov Nov 04 '22 at 11:32
  • @akostadinov Almost all GNU software has man pages that are just summaries, and the complete documentation in info or HTML only. – Gilles 'SO- stop being evil' Nov 04 '22 at 12:26
27

According to info coreutils ls (which might not be exactly what you have):

`s'
If the setuid or setgid bit and the corresponding executable bit are both set.

`S'
If the setuid or setgid bit is set but the corresponding executable bit is not set.

The number after the permission part is the number of hard links.

Mat
  • 52,586
10

In (hopefully simpler) terms, this means. The directory is setgid. Any files created in there will be owned by that group of the owner of that folder.

However, the folder is not executable by the group, so it's shown in capital S. This is typically when a directory is being created and the directory will end up as setgid.

Hm.. Not sure if that actually sounded like plain English above..

Jag
  • 111
  • 1
    This answer doesn't give any more or different information than existing answers. – jayhendren Dec 06 '16 at 00:35
  • 3
    @jayhendren Yes it does. It talks about directories. No other answer does that. (Gilles should probably incorporate his comment into his answer.) – Sparhawk Aug 23 '17 at 07:19
5

It's because of Executable is missing

s --> 'x' is enabled S --> 'x' is disabled.

see below example

$ ls -l

total 0

-rwsrw-r--. 1 bpkmails bpkmails 0 Jun 25 20:18 ca

$ chmod u-x ca

$ ls -l

total 0

-rwSrw-r--. 1 bpkmails bpkmails 0 Jun 25 20:18 ca

$
Stephen Kitt
  • 434,908
1

consider also umask, shell setting that subtracts that value to full access (666 for files, 777 for dirs) on file creation.

The standard behaviour of setuid/setgid is to propagate from parent to child directories

One can get 'S' permission on dirs with this command sequence, (check umask 077, ...):

~/test$ id
uid=1004(dsuser) gid=100(users) 
~/test$ 
~/test$ umask
0002
~/test$ 
~/test$ mkdir aaa
~/test$ ls -l
total 4
drwxrwxr-x 2 dsuser users 4096 Nov  5 14:57 aaa
~/test$ chmod g+s aaa
~/test$ ls -l
total 4
drwxrwsr-x 2 dsuser users 4096 Nov  5 14:57 aaa
~/test$ cd aaa
~/test/aaa$ 
~/test/aaa$ mkdir bbb
~/test/aaa$ ls -l
total 4
drwxrwsr-x 2 dsuser users 4096 Nov  5 14:58 bbb
~/test/aaa$

~/test/aaa$ umask 077 ~/test/aaa$ ~/test/aaa$ mkdir ccc ~/test/aaa$

~/test/aaa$ ls -l

total 8 drwxrwsr-x 2 dsuser users 4096 Nov 5 14:58 bbb drwx--S--- 2 dsuser users 4096 Nov 5 14:59 ccc

hute37
  • 21
  • taken from Julia strange installation permissions: https://github.com/JuliaLang/julia/issues/12876 – hute37 Nov 05 '20 at 14:10