Difference between a hard link and a symbolic link

Julian Villegas
Basics Full Stack Engineering
2 min readSep 17, 2019

Links in UNIX are pointers pointing to a file or a directory. Creating links is a kind of shortcuts to access a file. Links allow more than one file name to refer to the same file, elsewhere.

There are two types of links :

  1. Soft Link or Symbolic links. Refer to a symbolic path indicating the abstract location of another file
  2. Hard Links. Refer to the specific location of physical data.

The ln option make links between files. Let’s explore the man page for ln command

man page for ln command

Case Study and differences

Soft links are created with the ln -s command. For example, the following would create a soft link named __ls__ to a file program named ‘ls’ in /bin directory.

This script, link a file in the working directory with the original located in other directory.

If we modify the linked file, it updates in the original file. The main operation too is that if you delete the soft link, the original remain on disk; but if we delete the original file, the softlinks will become useless!

Hard links are more flexible and remain linked even if the original or linked files are moved throughout the file system (still contain the data that were in the original file), although hard links are unable to cross different file systems.

  • Links have actual file contents and same file size
  • Removing any link, just reduces the link count, but doesn’t affect other links.
  • Command to create a hard link is: $ ln [original filename] [link name]

--

--

Julian Villegas
Basics Full Stack Engineering

Professional System Engineer and Student at Holberton School Colombia