60 likes | 68 Views
Learn about hard links and soft links in Unix, how they provide backup and reference to files, and their differences and limitations.
E N D
Hard Linkwhen a file is copied, both the original and copy occupy separate space on the disk.unix allows a file to have more than one name and yet maintain a single copy on the disk. The file is then said to have more than one link or name, but all have the same inode number. This is called hard link. All attributes are identical any modification or change in one file is automatically available in the linked file. It provides some protection against accidental deletion. Let there be a file named restore.sh. You need to create another file which provides as backup to the original file. By creating a link, you create a backup.unix command used to create hard link >>ln- backup.sh restore.sh
Soft LinkIt doesn't have the file's content but simply provids pathname of that automatically has the contents. This is called as softlink. but incase the original file is deleted we can't get the file's content from the linked file, coz, it just provides the path name of the file. This is also known as symbolic link. Windows shortcuts are more like symbolic links. The original file and the linked files have different inode nos.Unix command used to create soft link>>ln-s
Hard Link: • ln [existing_file] [linked_file] • A directory entry containing the same “i-node number” of a file. All files have at least one hard-link - when removed, the link is removed • Symbolic Link: ln -s [existing_file] [linked_file] • A directory entry containing pathname to file (i.e. a pointer). Unlike hard links, i-node numbers can be different, but possess other useful features.
Hard Link Vs Symbolic Link • A Hard link is a UNIX path name for a file • ln /usr/mary/abc /usr/mary/xyz • Symbolic links are created with the –s option • ln –s /usr/mary/abc /usr/mary/xyz • Limitations of hardlinks: • Cannot create hardlinks for directories unless they have superuser privileges • Users cannot create hardlinks on a file system that references files on a different system.
ln Vs cp ln creates a new directory entry to a referenced file whereas cp creates a duplicated copy of the file to another file with a different name. ln /usr/mary/abc /usr/mary/xyz (ln –s)/ cp /usr/mary/abc /usr/mary/xyz