Using the list command (ls -l)

This may not be in the right place but I did not know how to search for this information.
When using the ls -l command to get additional information; there is one column that I do not know what it means.
Example:
drwxr-xr-x 2 root root…

The number 2 that is what I don’t know about. If you do an ls -l in any directory you will get all kinds of different numbers in that column.
Would someone be able to tell me what that column represents?

Thank you,

according to man ls 1p it is the number of links which seem to be basically number of sub-directories (+ links maybe)

On 2012-05-08 05:06, aldistuck wrote:

> Example:
> drwxr-xr-x 2 root root…
>
> The number 2 that is what I don’t know about. If you do an ls -l in
> any directory you will get all kinds of different numbers in that
> column.

I’m not sure. I think it is name entries. For files, 2 entries means that
there is one hard link to it. With directories a 2 means it has no
subdirectories, or rather 2: “.” and “…”. A 5 means 3 subdirectories.

But I haven’t seen this documented.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On 05/07/2012 10:06 PM, aldistuck wrote:
>
> This may not be in the right place but I did not know how to search for
> this information.
> When using the ls -l command to get additional information; there is
> one column that I do not know what it means.
> Example:
> drwxr-xr-x 2 root root…
>
> The number 2 that is what I don’t know about. If you do an ls -l in
> any directory you will get all kinds of different numbers in that
> column.
> Would someone be able to tell me what that column represents?

That is the size of the file in bytes.

The number of bytes is in the fifth column btw and the OP ask for the second column.

It is the number of hard links a file has.


henk@boven:~/test> ls -l
totaal 0
henk@boven:~/test> touch aap
henk@boven:~/test> ls -l
totaal 0
-rw-r--r-- 1 henk wij 0  8 mei 10:35 aap
henk@boven:~/test> ln aap noot
henk@boven:~/test> ls -l
totaal 0
-rw-r--r-- 2 henk wij 0  8 mei 10:35 aap
-rw-r--r-- 2 henk wij 0  8 mei 10:35 noot
henk@boven:~/test>

Now the following often amazes people:

henk@boven:~/test> ls -la
totaal 8
drwxr-xr-x  2 henk wij 4096  8 mei 10:35 .
drwxr-xr-x 83 henk wij 4096  8 mei 10:10 ..
-rw-r--r--  2 henk wij    0  8 mei 10:35 aap
-rw-r--r--  2 henk wij    0  8 mei 10:35 noot
henk@boven:~/test>

Why does … have 83 hard links? As you all know … is the parent directory (in this case it is ~, my home directory. And it has the name henk, but it has also the name . (inside itself) and het has 81 times the name … (in each of the 81 subdirectories it has).

I think this fits very well with what @Carlos and @gogalthorp allready found, but where not quite sure of.

On 2012-05-08 10:46, hcvv wrote:

> Why does … have 83 hard links? As you all know … is the parent
> directory (in this case it is ~, my home directory. And it has the name
> -henk-, but it has also the name . (inside itself) and het has 81 times
> the name … (in each of the 81 subdirectories it has).

Ah…!

Those entries are considered links, too.

I haven’t seen this simple explanation in the man, though mans are not
known for clarity.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Well, they are not “considered”, they are hard links. Exactly the same technical mechanism as the hard links you know: an entry in the directory three pointing to the same disk address as another entry.

And yes, man pages tend to tell you exactly what is needed and not a sylable more. Thus you may be told that the column shows number of links. But it will not explain what a link is and not that thus a directory will have at least two and one more for every subdirectory. After all* ls *lists only, it is not the place to teach about hard links, owners, groups, access bits, time stamps, etc.

On Tue, 08 May 2012 17:06:02 +0530, hcvv <hcvv@no-mx.forums.opensuse.org>
wrote:

>
> robin_listas;2461301 Wrote:
>>
>> Those entries are considered links, too.
>>
>> I haven’t seen this simple explanation in the man, though mans are not
>> known for clarity.
>>
>>
> Well, they are not “considered”, they are hard links. Exactly the same
> technical mechanism as the hard links you know: an entry in the
> directory three pointing to the same disk address as another entry.
>
> And yes, -man- pages tend to tell you exactly what is needed and not a
> sylable more. Thus you may be told that the column shows number of
> links. But it will not explain what a link is and not that thus a
> directory will have at least two and one more for every subdirectory.
> After all- ls -lists only, it is not the place to teach about hard
> links, owners, groups, access bits, time stamps, etc.
>

<ot>can’t help but observe that at times carlos’ own style, when
‘explaining’ something to potentially new linux users, appears even
shorter than ‘man’ style…</ot>


phani.

On 2012-05-08 13:36, hcvv wrote:

> Well, they are not “considered”, they are hard links. Exactly the same
> technical mechanism as the hard links you know: an entry in the
> directory three pointing to the same disk address as another entry.

It reflects that the only filesystem I know in depth is FAT :-}

>
> And yes, -man- pages tend to tell you exactly what is needed and not a
> sylable more. Thus you may be told that the column shows number of
> links. But it will not explain what a link is and not that thus a
> directory will have at least two and one more for every subdirectory.
> After all- ls -lists only, it is not the place to teach about hard
> links, owners, groups, access bits, time stamps, etc.

Well…

Not everything needs to be explained, but something more would be appreciated.

In the time of Unix, where changes were limited, you had books to learn,
and man pages as reminder. With Linux, progress goes so fast that books
become obsolete too soon, so we have to use online/onsystem docs mostly.
Thus better man pages would be appreciated - or a better system than man
pages, with hyperlinks, etc. Info pages were a better approach. Thus, when
explaining the fields of the ls display, you can say that the second column
are links, and link to a deeper explanation.

(no, the info page for ls doesn’t explain it either - I’m just looking at it)


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On 2012-05-08 13:53, phanisvara das wrote:
> On Tue, 08 May 2012 17:06:02 +0530, hcvv <hcvv@no-mx.forums.opensuse.org>
> wrote:

> <ot>can’t help but observe that at times carlos’ own style, when
> ‘explaining’ something to potentially new linux users, appears even shorter
> than ‘man’ style…</ot>

O:-)

(I don’t know what that “<ot>” means, if it is a token the forum software
should interpret. Or perhaps it is off-topic?)

Sometimes I give only a hint, sometimes I write a long explanation,
depending on the time I have available and what I think is needed. I
recognize that sometimes a newcomer may not understand, but I gladly expand
on request. When I write docs, I write a lot, expending days over it. As an
example, have a look here, I wrote it all:

Offline upgrade method


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On Tue, 08 May 2012 17:53:06 +0530, Carlos E. R.
<robin_listas@no-mx.forums.opensuse.org> wrote:

> On 2012-05-08 13:53, phanisvara das wrote:
>> On Tue, 08 May 2012 17:06:02 +0530, hcvv
>> <hcvv@no-mx.forums.opensuse.org>
>> wrote:
>
>
>> <ot>can’t help but observe that at times carlos’ own style, when
>> ‘explaining’ something to potentially new linux users, appears even
>> shorter
>> than ‘man’ style…</ot>
>
> O:-)
>
> (I don’t know what that “<ot>” means, if it is a token the forum software
> should interpret. Or perhaps it is off-topic?)

yes, what i meant was “off-topic”. i thought i’d seen this type of ‘tag’
before, but not sure. obviously not self-explanatory…

> Sometimes I give only a hint, sometimes I write a long explanation,
> depending on the time I have available and what I think is needed. I
> recognize that sometimes a newcomer may not understand, but I gladly
> expand
> on request.

i remembered a small ‘scuffle’ you had with one of the moderators or
admins here (henc?) recently, and i also remember some of your really
concise replies.

> When I write docs, I write a lot, expending days over it. As an example,
> have a look here, I wrote it all:
>
> Offline upgrade
> method

>

wow, that’s a lot of writing, and well done.


phani.

> mans are not known for clarity.


info ls

is instructive with “number of hard link” immediately preceding the
owner name:


-l
--format=long
--format=verbose
In addition to the name of each file, print the file type, file
mode bits, number of hard links, owner name, group name, size, and
timestamp" . . .


dd

On 2012-05-08 15:23, dd@home.dk wrote:
>> mans are not known for clarity.
>
>


> info ls
> 

>
> is instructive with “number of hard link” immediately preceding the owner
> name:

It does not have a “*note…::” link, that is, it does not explain what it
implies. Or, it does not have an example.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

On 05/08/2012 03:53 PM, Carlos E. R. wrote:
> It does not have a “*note…::” link, that is, it does not explain what it
> implies. Or, it does not have an example.

i quoted a small portion of the entire “note” offered for the -l switch…

if you need an example, just do an “ls -l” and look at it, or here is
one from my machine:


-rw-r--r--  1 dd users     166 Feb 21 11:47 sigSUSE

look at that while reading the ls info (which i will quote in full this
time–see that between the file mode bits and the owner name is the
“number of hard links”):


In addition to the name of each file, print the file type, file
mode bits, number of hard links, owner name, group name, size, and
timestamp (*note Formatting file timestamps::), normally the
modification time.  Print question marks for information that
cannot be determined.

Normally the size is printed as a byte count without punctuation,
but this can be overridden (*note Block size::).  For example, `-h'
prints an abbreviated, human-readable count, and
`--block-size="'1"' prints a byte count with the thousands
separator of the current locale.

For each directory that is listed, preface the files with a line
`total BLOCKS', where BLOCKS is the total disk allocation for all
files in that directory.  The block size currently defaults to 1024
bytes, but this can be overridden (*note Block size::).  The
BLOCKS computed counts each hard link separately; this is arguably
a deficiency.

The file type is one of the following characters:

`-'
regular file

`b'
block special file

`c'
character special file

`C'
high performance ("contiguous data") file

`d'
directory

`D'
door (Solaris 2.5 and up)

`l'
symbolic link

`M'
off-line ("migrated") file (Cray DMF)

`n'
network special file (HP-UX)

`p'
FIFO (named pipe)

`P'
port (Solaris 10 and up)

`s'
socket

`?'
some other file type

The file mode bits listed are similar to symbolic mode
specifications (*note Symbolic Modes::).  But `ls' combines
multiple bits into the third character of each set of permissions
as follows:

`s'
If the set-user-ID or set-group-ID bit and the corresponding
executable bit are both set.

`S'
If the set-user-ID or set-group-ID bit is set but the
corresponding executable bit is not set.

`t'
If the restricted deletion flag or sticky bit, and the
other-executable bit, are both set.  The restricted deletion
flag is another name for the sticky bit.  *Note Mode
Structure::.

`T'
If the restricted deletion flag or sticky bit is set but the
other-executable bit is not set.

`x'
If the executable bit is set and none of the above apply.

`-'
Otherwise.

Following the file mode bits is a single character that specifies
whether an alternate access method such as an access control list
applies to the file.  When the character following the file mode
bits is a space, there is no alternate access method.  When it is
a printing character, then there is such a method.

GNU `ls' uses a `.' character to indicate a file with an SELinux
security context, but no other alternate access method.

A file with any other combination of alternate access methods is
marked with a `+' character.

better?


dd

Thank you all for the in depth replies.
It’s things like that, that I don’t normally pay attention to and then one day I see it and wonder why it’s there.

I aplaud people doing things like asking themselves now and then: “do I realy understand this?”. It helps enourmously in increasing your Unix/Linux knowledge because you then get that bit of information when you ask for it. When you get the same information fed to you during a course mixed with hundreds of other things, it will go (like a Dutch saying goes) “one ear in and the other out again”.