Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-15-2011, 04:11 PM   #1
Registered: Nov 2008
Location: Brazil
Distribution: Manjaro
Posts: 105

Rep: Reputation: 18
ls long listing format - number of hard links / directories


I have a question regarding the 'ls -l' command - what does the 'number of linked hard-links' mean when the file is a directory?
Old 09-15-2011, 04:36 PM   #2
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Even for directories, it should still refer to hard links.


$ mkdir foo

$ ls -ld foo
drwxr-xr-x 2 me me 4096 Sep 15 15:32 foo
Right now there are two hard links:
  • foo
  • foo/.

The latter is the directory's reference to itself.

Let's create some stuff inside it:

$ touch foo/bar foo/baz

$ mkdir foo/boo

$ ls -ld foo
drwxr-xr-x 3 me me 4096 Sep 15 15:34 foo
Now there are three hard links for the directory. Why? Because now we have:
  • foo
  • foo/.
  • foo/boo/..

The last entry is the parent of boo (which is foo). If we create more subdirectories inside foo, the hard links will increase accordingly.

Last edited by anomie; 09-15-2011 at 04:37 PM. Reason: clarified. hopefully.
1 members found this post helpful.
Old 09-15-2011, 04:47 PM   #3
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,820
Blog Entries: 15

Rep: Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664
Hard links are refrences to the same inode (as opposed to file) on a given filesystem. Hard links do not take up any more space because all the space is in the original file.

Soft links (a/k/a symbolic links and slinks) are references to a file and do not have to be on the same filesystem as the original file. Each slink takes up a tiny amount of space.

The most common default hard links to a directory are the "." and ".." seen in subdirectory paths below it. The "." in a directory is shorthand for "this directory" and the ".." is shorthand for "the parent directory of this directory".

Of course you can use the ln (link) command to create additional hard links or soft links to any given file. (Note that a directory is a "file" in UNIX/Linux.)
1 members found this post helpful.
Old 09-15-2011, 05:43 PM   #4
Registered: Nov 2008
Location: Brazil
Distribution: Manjaro
Posts: 105

Original Poster
Rep: Reputation: 18
Thanks folks, I'm currently teaching informatics for the little ones (10/11 years old) and I tough them how to make hard and soft links, and the long listing format, and now I can explain to them this topic better.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
maximum number of hard links hydraMax Linux - Server 1 12-08-2010 02:48 AM
Listing hard and soft links to a file! muasif80 Linux - Newbie 1 10-04-2008 11:10 PM
Hard links Number and Directories ahmedb72 Solaris / OpenSolaris 2 07-04-2007 02:54 PM
Why we can't create hard links for directories in linux? tdhanu_2000 Linux - Kernel 11 06-11-2006 05:14 AM
How to format a long double number in C++ to display as many digits as possible. TruongAn Programming 4 11-09-2005 11:11 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration