What is the difference between a hard link and a symbolic link?

Abidi Ghofrane
4 min readSep 17, 2019

--

what’s a symbolic link and a hard link?

What is a link in Linux?

In your Linux file system, a link is a connection between a file name and the actual data on the disk. There are two main types of links that can be created: “hard” links, and “soft” or symbolic links. Hard links are low-level links which the system uses to create elements of the file system itself, such as files and directories.

What is a symbolic link?

A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias. A symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system. This difference gives symbolic links certain qualities that hard links do not have, such as the ability to link to directories, or to files on remote computers networked through NFS. Also, when you delete a target file, symbolic links to that file become unusable, whereas hard links preserve the contents of the file.

how to create a symbolic link?

What is a hard link ?

A hard link is merely an additional name for an existing file on Linux or other Unix-like operating systems.

Any number of hard links, and thus any number of names, can be created for any file. Hard links can also be created to other hard links. However, they cannot be created for directories, and they cannot cross filesystem boundaries or span across partitions.

The operating system makes no distinction between the name that was originally assigned to a file when it was first created and any hard links that are subsequently created to that file other than that they are merely multiple names for the same file. This is because the original name and any hard links all point to the same inode. An inode is a data structure (i.e., an optimized way of storing information) that stores all the information about a file (e.g., its size, its access permissions, when it was created and where it is located on the system) except its name(s) and its actual data. The fact that inode numbers are unique only within any filesystem is the reason that they do not work across filesystems and partitions.

how to create a hard link ?

How to tell the difference between the two of them?

Soft Links (symbolic links)

You can make links to files and directories, and you can create links (shortcuts) on different partition and with a different inode number from original. If the real copy is deleted, the link will not work.

Hard Links

Hard links are for files only; you cannot link to a file on different partition with a different inode number. If the real copy is deleted the link will work, because it accesses the underlying data the real copy was accessing.

You can tell if a file has a hard link by using the ls command:

A standard file without links will look as follows

If this was a hard link the output would look as follows:

A symbolic link will look as follows:

Enjoy Linux! :)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Abidi Ghofrane
Abidi Ghofrane

Written by Abidi Ghofrane

Software engineering student at Holberton School Tunis

No responses yet

Write a response