Tuesday, 16 October 2012

SOFT & HARD LINKS



Soft Link:
            Symbolic link is a file that points to another file, and can create symbolic links for files, directories, and device files also

            Syntax: ln -s <source_file> <target_file>
                          #ln –s /var/file1 link1

  1. The size of the symbolic link always matches the number of characters in the path name it contains. EX: bin -> ./usr/bin  [ size of bin directory is : 9]
  2. Inode values are different but data block are same for soft link.
  3. Across file system or network or another disk we can create the symbolic links
  4. We can identify the soft link by using command ls –F which it displays the @ symbol at the end of the link
# ls -F
Desktop/     bin@         devices/     export/      lib/         net/         proc/        tmp/        
Documents/   boot/        etc/         home/        lost+found/  opt/         sbin/        usr/
anonFTP/     dev/         evolution/   kernel/      mnt/         platform/    system/      var/
# ls -l bin
lrwxrwxrwx   1 root     root           9 Sep  8 19:06 bin -> ./usr/bin
  1. We can create the soft links for non existence source also#ln -s sur1 sub2 [here both files non existence files]
  1. We can remove symbolic links by using rm command#rm link1
Hard Links:
  1. We can create hard links for files only, and can’t create the hard links across the file system
  2. Inode values are always same but data block are differect and will occupy the disk space
  3. We can identify hard links by using link count more than 1
# ls -li /etc/rc2.d/K05appserv
      5425 -rwxr--r--   5 root     sys          824 Aug 16  2006 /etc/rc2.d/K05appserv
#find / -mount –inum 5425 –exec ls –ltr  {} \;
5425    1 -rwxr--r--   5 root     sys           824 Aug 16  2006 /etc/init.d/appserv
 5425    1 -rwxr--r--   5 root     sys           824 Aug 16  2006 /etc/rc0.d/K05appserv
 5425    1 -rwxr--r--   5 root     sys           824 Aug 16  2006 /etc/rc1.d/K05appserv
 5425    1 -rwxr--r--   5 root     sys           824 Aug 16  2006 /etc/rc2.d/K05appserv
 5425    1 -rwxr--r--   5 root     sys           824 Aug 16  2006 /etc/rc3.d/S84appserv
Or
# find / -inum 5425
/etc/init.d/appserv
/etc/rc0.d/K05appserv
/etc/rc1.d/K05appserv
/etc/rc2.d/K05appserv
/etc/rc3.d/S84appserv


Flipkart.com