Find the answer to your Linux question:
Results 1 to 5 of 5
Hey guys and girls I'm studying my Linux+ at the moment and am a complete noob to Linux. One of the things I'm reviewing is links and have the following ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Location
    South Africa
    Posts
    3

    Question [SOLVED] Why use hard links instead of soft links


    Hey guys and girls

    I'm studying my Linux+ at the moment and am a complete noob to Linux. One of the things I'm reviewing is links and have the following question.

    Why use hard links instead of soft links

    I've one some tests, creating both hard links and soft links to the same file, and when I do a ls -la and look at the file properties it appears that the hard link makes a complete copy of the file, while the soft link only makes a link (like a MS shortcut) to the file. The way I get to this conclusion, is that the hard link is the same size as the actual file, but the soft link is much smaller in size (like a shortcut would be)

    I'd appreciate any feedback if I'm incorrect (which I probably am)

    Thanx in advance
    Acidean

  2. #2
    Linux Engineer b2bwild's Avatar
    Join Date
    Jul 2008
    Location
    Behind You!
    Posts
    1,108
    No, hard link represents the i-node enrty.
    Where the soft link represts the file name and its path.

    do one experiment.
    Create one file now create 1 hard link and 1 soft link.
    then execute ls -il in folder
    # ls -il
    You will notice, Hard Link and File have same Inode
    Where as Soft Link is like shortcut and a different file, so it will have different inode.


    EDIT: I will do that for you
    pratik@pratik-desktop:~$ mkdir test
    pratik@pratik-desktop:~$ cd test/
    pratik@pratik-desktop:~/test$ touch hehe
    pratik@pratik-desktop:~/test$ ln hehe hehehe
    pratik@pratik-desktop:~/test$ ls -il
    total 0
    2285731 -rw-r--r-- 2 pratik pratik 0 2009-02-18 13:40 hehe
    2285731 -rw-r--r-- 2 pratik pratik 0 2009-02-18 13:40 hehehe

    pratik@pratik-desktop:~/test$ ln -s hehe haha
    pratik@pratik-desktop:~/test$ ls -il
    total 0
    2285732 lrwxrwxrwx 1 pratik pratik 4 2009-02-18 13:40 haha -> hehe
    2285731 -rw-r--r-- 2 pratik pratik 0 2009-02-18 13:40 hehe
    2285731 -rw-r--r-- 2 pratik pratik 0 2009-02-18 13:40 hehehe

    pratik@pratik-desktop:~/test$
    Just observe.
    Never make any misteaks.

    Read my Blog at --> Penguin Inside Subscribe Feed

  3. #3
    Just Joined!
    Join Date
    Feb 2009
    Location
    South Africa
    Posts
    3
    Ok, so let me see if I understand this correctly...

    Every file created on a Linux box receives a i-node entry. This i-node entry is effectively the "file name" from the reference point of view. The file name that we as uses see, as well as the hard link is effectively a link to the i-node entry (which is like a shortcut). A soft link, is then a link to a hard link, which in turn is a link to the i-node entry.

    So in short, the i-node entry is the file, the file name is a hard link and a soft link is a "shortcut" to a hard link.

    Is this understanding correct ?

    Thanx

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer b2bwild's Avatar
    Join Date
    Jul 2008
    Location
    Behind You!
    Posts
    1,108
    If you read the documentation on inode, available on the internet. Its really hard to understand. cause its explained in big walls of text.

    In simple term
    There is inode table in filesystem.
    each inode entry holds the information about the file
    i.e. its physical location on the drive, path of file, and other
    each entry have a number. called as "inode"

    Hard Link is the duplication of inode,
    Where soft link is just a shortcut. when we read the hard link we are reading the original file.. so it shows us the real size of file.

    So yes you are right. you can call the hard link as acutal file
    cause when you delete the Original file, soft link will die where hard link and file will be still usable.
    Never make any misteaks.

    Read my Blog at --> Penguin Inside Subscribe Feed

  6. #5
    Just Joined!
    Join Date
    Feb 2009
    Location
    South Africa
    Posts
    3
    Ok brilliant, now I get it

    Thank you very much for your help

Posting Permissions

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