What’s the Deal With Hard Links and Symbolic Links?

Miranda Evans
3 min readJan 16, 2018

--

You have a file, and you want to link to that file under another name. Do you use a hard link or a symbolic link?

To understand the difference between a hard link or a symbolic link, you must understand how computers work. A computer’s hard drive is comprised of a series of switches, which are represented by 1’s and 0’s. A file on a computer is a collection of data that has a specific, physical location somewhere in the midst of those 1’s and 0’s (and is a series of 1’s and 0’s itself). Therefore, to access a file, we must know where the data of the file is physically stored. An inode is a data structure that contains a pointer to the location of the data, as well as some other pieces of metadata.

You may be wondering how this fits into the file system on your computer. After all, you don’t name your files “inode1”, “inode2”… As it turns out, the filenames on your computer point to inodes, and the directories on your computer are simply a handy way of organizing filenames. Inodes are an intermediary between what you choose to name your data and the data itself.

This is where hard vs. symbolic links come in. Let’s say you create a file called “Abby.” Your computer creates a link from the filename Abby to an inode, and from the inode to the location of Abby’s data. Then you create a hard link called “Betty.” Betty points to the same inode that Abby does. Finally, you create a symbolic link called “Connie.” Connie does not point to an inode, but rather points to the filename Abby.

The command touch [filename] creates a file, ln [filename] [hardlink] creates a hard link, and ln -s [filename] [symbolic link] creates a symbolic link. In the picture below, touch Abby creates the original file, ln Abby Betty creates the hard link, and ln -s Abby Connie creates the symbolic link. For more information, enter man ln in your terminal for the manual page.

So why use one over the other? Well, there are pros and cons to both. If you move or delete the original filename Abby, Betty still points to the inode so it still contains the data, whereas Connie no longer points to anything and is useless. If Abby is on your computer and you utilize a second filesystem, by plugging in a USB flash drive for example, and try to create Betty and Connie on the flash drive, Connie the symbolic link will work because it is simply a link to the filename Abby, whereas Betty the hard link will not work because it is on a separate filesystem and cannot point to the inode on your computer. In the picture below, Connie was broken because Abby changed to Danny.

If you need to have a file on more that one place in your filesystem, or your original file is getting moved around, or if it is a big file that you need to work quickly, a hard link is good to use. If you need to link to a directory, or if you are moving files to other filesystems, you will need to use a symbolic link. For a table of capabilities of hard and symbolic links, see this page.

--

--