Ubuntu – What does the second column in the output of ‘ls -n’ mean

command linels

When I run:

ls -n

I get something like:

-rwxrwxrwx  1 1000 1000   765528 2009-10-15 18:41 file1
drwxr-xr-x 10 1000 1000     4096 2010-12-07 20:50 dir1
drwxr-xr-x  3 1000 1000     4096 2010-10-24 16:57 dir2

What does the second column (the number) mean?

Best Answer

The second column is the number of hard links to the file. For a directory, the number of hard links is the number of immediate subdirectories it has plus its parent directory and itself.

$ ls -n
total 0
$ touch f1
$ touch f2
$ ln f1 hardlink
$ ln -s f2 softlink
$ mkdir d1
$ mkdir d2
$ mkdir d2/a d2/b d2/c
$ ls -n
total 8
drwxr-xr-x 2 1000 1000 4096 2010-12-31 00:07 d1
drwxr-xr-x 5 1000 1000 4096 2010-12-31 00:07 d2
-rw-r--r-- 2 1000 1000    0 2010-12-31 00:06 f1
-rw-r--r-- 1 1000 1000    0 2010-12-31 00:06 f2
-rw-r--r-- 2 1000 1000    0 2010-12-31 00:06 hardlink
lrwxrwxrwx 1 1000 1000    2 2010-12-31 00:07 softlink -> f2

Linux Gazette Issue 35

Linux Gazette Issue 93