0

I'd like to ask some help with a question about "ls" program: could please anyone explain what does the second field of "ls -l" output mean?

Here is an example:

sergey@home-ubuntu:~$ ls -l total 64 drwxr-xr-x 8 sergey sergey 4096 мая 12 11:54 Desktop drwxr-xr-x 5 sergey sergey 4096 апр 28 00:09 Documents drwxr-xr-x 10 sergey sergey 12288 мая 12 23:22 Downloads drwxrwxr-x 3 sergey sergey 4096 апр 12 15:22 Games drwxrwxr-x 7 sergey sergey 4096 апр 2 23:02 MEGAsync drwxr-xr-x 3 sergey sergey 4096 апр 15 21:18 Music drwxr-xr-x 4 sergey sergey 4096 мая 7 09:10 Pictures drwxr-xr-x 2 sergey sergey 4096 апр 2 22:24 Public drwxrwxr-x 4 sergey sergey 4096 апр 9 17:57 Scripts drwxr-xr-x 5 sergey sergey 4096 апр 16 22:42 snap drwxrwxr-x 3 sergey sergey 4096 мая 9 21:20 Soft drwxr-xr-x 2 sergey sergey 4096 апр 2 22:24 Templates drwxrwxr-x 3 sergey sergey 4096 мая 12 23:39 Tests drwxr-xr-x 3 sergey sergey 4096 мая 12 16:11 Videos ^ this field i'm interested in 

The internet says it shows the number of links to a file, wikipedia specifies to hard links, but i couldn't find any information about directories, yet it's represented in ls -l output.

Since one can't create a hard link to a folder, it's unclear what that field means.

2
  • 1
    Does unix.stackexchange.com/questions/43046/… help? ("the number of contained directory entries, when referring to a directory.") Commented May 12, 2020 at 18:53
  • @JeffSchaller, i'm a little too late with my answer, but yes, your link does help. Thank you! Commented Nov 20, 2023 at 5:41

1 Answer 1

0

From info ls:

‘-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 (*note Formatting file timestamps::), normally the modification timestamp (the mtime, *note File timestamps::). Print question marks for information that cannot be determined.

So, yes, that is the number of hard links.But what does it mean?

Simple: quite similar to the number of files in the directory.

At the start, when a directory is created, it starts with two hard links (think of that as the hard links for . and ..)

$ mkdir anewone $ ls -lad anewone drwxr-xr-x 2 isaac isaac 4096 May 12 18:29 anewone ...........^^..... 2 hard links. 

As you create new sub-directories in that directory, the number of hard links increase:

$ touch anewone/{a..e} $ ls -lad anewone drwxr-xr-x 2 isaac isaac 4096 May 12 18:30 anewone ...........^^..... No change for files. $ mkdir anewone/{f..m} $ ls -lad anewone drwxr-xr-x 10 isaac isaac 4096 May 12 18:30 anewone ...........^^..... 8 new directories ==> 10 hard links. 

Related:

Why does a new directory have a hard link count of 2 before anything is added to it?

hardlink count for directory

1
  • Thank you! Never thought that these ".." are actually hard links. Commented May 13, 2020 at 4:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.