[File system] Hard link and soft link

Home Forums Linux Questions & Answers.. Filesystem .. [File system] Hard link and soft link

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1950 Reply
    Humble
    Keymaster

    Can you explain what are hard and soft links? whats the difference between these?

    #2454 Reply
    Humble
    Keymaster

    Well, common thing.. but let me put it in this way..

    As everyone says, it comes into category of “link” files..

    Hardlink:

    Well, hard links point to the same INODE .. but the file names are different and both filenames point to the same inode..

    You can create hardlink with ln command as shown below:

    [root@humbles-lap ]# ln foo.bar foo1.bar1
    [root@humbles-lap ]# ls -li foo*
    9443948 -rw-rw-r--. 2 hchiramm hchiramm   0 Jul 14  2013 foo1.bar1
    9443948 -rw-rw-r--. 2 hchiramm hchiramm   0 Jul 14  2013 foo.bar
    
    [root@humbles-lap ]# 
    
    
    
    
    
    
    In first line, we created "hardlink" to the file called "foo.bar" in name of "foo1.bar1".. 
    
    How-ever you can see both have same INODE number.. 
    
    
    You can only have hardlinks within same filesystem. Also directories can not be hard linked..
    
    Symlinks:
    
    symlinks are actually  a special file containing a path to another file. 
    When you operate on 'symlinked' filename , it actually access the file which is pointed inside symlink file. In short, symlinks store  the path of the file it points too. Unlike hardlinks, symlinks can be on different filesystems.. 
    
    With "-s" option of "ln" command you can create symlinks.. Please note that symlinks will have different inode numbers.. 
    
    
    
    [root@humbles-lap ]# ln -s foo.bar foo.soft
    [root@humbles-lap ]# ls -li foo*
    9443948 -rw-rw-r--. 2 hchiramm hchiramm   0 Jul 14  2013 foo1.bar1
    9443948 -rw-rw-r--. 2 hchiramm hchiramm   0 Jul 14  2013 foo.bar
    9449878 lrwxrwxrwx. 1 root     root       7 Feb 21 00:16 foo.soft -> foo.bar
    [root@humbles-lap ]# 
    
    
    Please note, l in lrwxrwxrwx ..
    #2459 Reply
    Humble
    Keymaster
    This reply has been marked as private.
Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: [File system] Hard link and soft link
Your information: