Want to Know: What Are Symbolic and Hard Links!?

Image for post
Image for post

If you’re someone who came here wanting to learn about a shortcut in Linux a little bit more about links on Linux, great! Let me try to break things down a little! Let’s start by thinking of our links in UNIX, as a “pointer” to a file or directory. Creating a link is like creating a shortcut. The shortcut points us directly to the file/directory we want to access.

More specifically, there are TWO types of links that we can use!

HARD LINKS

SYMBOLIC LINKS (also known as ‘soft’ links)

The main difference in these two links is the action taken when the source file/directory that the link is pointing to has been moved or removed. I will discuss the specifics behind what each link does when the source file/directory has been moved/removed and cases in which we would use each link.

HARD LINK

A hard link always refers to the source even if it has been moved/removed. Hard links have the same Inode (identification number) value as the original, so it is referencing the physical location of the source. Hard links are often used because of their flexibility, however they cannot cross different filing systems.

Use the syntax below to create a hard link:

Image for post
Image for post

SYMBOLIC LINK

A symbolic/soft link is not updated if the source is moved/removed. When attempting to use a soft link, if the original source is removed, then the link will not work correctly, or become what is referred to as a “hanging link”. Each file is given a separate Inode (Identification number) than the original. As opposed to hard links, soft links can be used across different filing systems! Essentially, soft links use the path of the file instead of the content inside of the file.

To create a symbolic/soft link, use the syntax below:

Image for post
Image for post

Hopefully, after reading this, you were able to gain a better understanding of what symbolic and hard links do on a Linux system. Remember, the more you understand the basics, the easier it will be to utilize the full potential of the Shell! Also remember to be safe, know when you’re operating as root, and have fun! Until next time!

Full-Stack Software Engineering Student at Holberton School

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