1 / 6

Understanding Hard and Soft Links in Unix

Learn about hard links and soft links in Unix, how they provide backup and reference to files, and their differences and limitations.

jnguyen
Download Presentation

Understanding Hard and Soft Links in Unix

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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.

  4. 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.

  5. Hard Link Vs Symbolic Link

  6. 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

More Related