Find the answer to your Linux question:
Results 1 to 3 of 3
Hello every one! I am having a little bit of difficulty in understanding the concepts on links especially hard links. Here is what i have understood till now (correct me ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3

    Links in Linux.

    Hello every one!

    I am having a little bit of difficulty in understanding the concepts on links especially hard links. Here is what i have understood till now (correct me where i am wrong):

    Hard links are just pointers to a physical location of a file. If a file has two hard links, means there are two pointers pointing at the same location and even if we remove one pointer, other can lend us in that location.

    Now here is what i dont understand:

    When I create directories e.g. mkdir -p /parent/child/childofchild/

    and when i "stat" all these directories, i find /parent with link count of 3, /parent/child with link count of 3 and /parent/childchildofchild with link count of 2. I dont understand which 3 pointers are pointing to /parent or /parent/child.

    If any body can help with that? Help will be appreciated.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Every component of a directory increments its link count, and the directory by itself has a link count of 1, so when you create child in parent, parent's count is 2. When you add a childofchild to child, both child and parent get their link counts incremented. Each time something is unlinked from a directory, its link count, and its parent link count is decremented. Until a file/directory's link count gets to 0, the operating system will not actually delete the entity.

    Anyway, you do seem to understand hard links pretty well. One caveat is that hard links can only be created in the same physical file system as the source file. Also, soft links don't increment the link count of the source file or directory, so if you delete the source, the link will still be there, but pointing to nowhere. It in effect becomes a special kind of local file with no contents. If, on the other hand, you were to recreate the file/directory the soft link is pointing at, you can again access it as you would the source.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    Thanks. Really appriciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...