Hard Link (on Linux)

Share

What are "Hard Links" on Linux?

A hard link is a filepath that represents a file. Every file Linux has at least one hard link, which is its initial filepath. Files are also called inodes in this context. You can create additional hard links with the terminal command ln. When you do this, you have two different filepaths that point to the same inode.

Most properties of a file are properties of the inode, not of the hard link that represents it, which means that all hard links will share it.

For example, if you modify the file using one hard link, all hard links will point to the modified file, since they all point to the same inode. The RWX file permissions are also stored in the inode. If you make a file read-only by removing the write permission, all hard links become read-only, otherwise you would be able to modify the file by using a different hard link.

If you need to have multiple copies of the same file, and you want updates to be automatically propagate to all filepaths or you want it to always be read-only, you can save disk space by making the copies hard links instead of separate files. This is one of the few cases in which hard links work. In general, however, hard links are very tricky to use since modifying a file will modify all the hard links, but you don't have any easy way of knowing what are all the filepaths to an inode, which means if you don't have a strict way of organizing your files, you may accidentally modify a file in 10 different places.

A similar but different concept are soft links, also called symbolic links or symlinks.

Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments