You can make links between files in Linux. There are two types of links: hard links and symbolic links. In this tutorial I will show you the differences between the two and how to create them.

Introduction

You can link files and directories, so any changes in one file (the TARGET) will be reflected in the other file (the LINK). There are two types of links: hard links and symbolic links.

Hard links are only possible with files on the same drive. You can use ln or link commands to create a hard link:

ln TARGET LINK_NAME
link TARGET LINK_NAME
  • LINK_NAME and TARGET are file paths.

If you remove the target file, link file will remain with the contents of the deleted file.

You can link folders and files on the same or different drives with symbolic links. You can use ln -s to create a symbolic link:

ln -s TARGET LINK_NAME
  • LINK_NAME and TARGET are file paths.

For example, if there is no python executable on the system, but python3.9 exists:

ln -s /usr/bin/python3.9 /usr/bin/python

If you remove the target file, link file will be unusable.

Test with this online terminal:

If you have any suggestion, feel free to contact me via social media or email.