Hard and Symbolic links on Linux

  1. Hard Links
  2. Soft Link or Symbolic links
  • Each hard linked file is assigned the same Inode value as the original, therefore they reference the same physical file location. Hard links more flexible and remain linked even if the original or linked files are moved throughout the file system, although hard links are unable to cross different file systems.
  • ls -l command shows all the links with the link column shows number of links.
  • Links have actual file contents
  • Removing any link, just reduces the link count, but doesn’t affect other links.
  • We cannot create a hard link for a directory to avoid recursive loops.
  • If original file is removed then the link will still show the content of the file.
  • Command to create a hard link is:
$ ln  [original filename] [link name]
  • A soft link is similar to the file shortcut feature which is used in Windows Operating systems. Each soft linked file contains a separate Inode value that points to the original file. As similar to hard links, any changes to the data in either file is reflected in the other. Soft links can be linked across different file systems, although if the original file is deleted or moved, the soft linked file will not work correctly (called hanging link).
  • ls -l command shows all links with first column value l? and the link points to original file.
  • Soft Link contains the path for original file and not the contents.
  • Removing soft link doesn’t affect anything but removing original file, the link becomes “dangling” link which points to nonexistent file.
  • A soft link can link to a directory.
  • Link across filesystems: If you want to link files across the filesystems, you can only use symlinks/soft links.
  • Command to create a Soft link is:
$ ln  -s [original filename] [link name]
  • Hard links cannot link to directories / folders / folders.
  • These cannot cross file system boundaries.
  • Create links between directories / folders / folders.
  • It can cross file system boundaries.
  • Symbolic links are not updated.
  • Hard links always refer to the source, even if moved or removed.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store