LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi,

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, 03:36 PM   #2
anomie
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.

Example:

Code:
$ 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:

Code:
$ 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 03:37 PM. Reason: clarified. hopefully.
 
1 members found this post helpful.
Old 09-15-2011, 03:47 PM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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, 04:43 PM   #4
sljunkie
Member
 
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.
 
  


Reply



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 01:48 AM
Listing hard and soft links to a file! muasif80 Linux - Newbie 1 10-04-2008 10:10 PM
Hard links Number and Directories ahmedb72 Solaris / OpenSolaris 2 07-04-2007 01:54 PM
Why we can't create hard links for directories in linux? tdhanu_2000 Linux - Kernel 11 06-11-2006 04:14 AM
How to format a long double number in C++ to display as many digits as possible. TruongAn Programming 4 11-09-2005 10:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:08 AM.

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