Create Symbolic Links in Linux
Create Symbolic Links in Linux
In this tutorial, you will learn how to create symbolic links in Linux. The ln command can be used to create both hard links and symbolic links.
What is an inode?
An inode( index node ) is a data structure that stores critical metadata information about a file or directory, except its name and actual data. It contains metadata such as:
- File size
- Ownership (user and group)
- Permissions (read/write/execute)
- Timestamps (created, modified, accessed)
- Pointers to the actual data blocks on the storage device
A link in Linux is a pointer to a file. The pointer associates the filename with an inode number. There are two kinds of links:
- Hard Links
- Symbolic/Soft Links
Soft Links
A soft link (symbolic link) is like a shortcut in Windows. It points to another file or directory by its name, not its actual data. If the original file is deleted, the soft link becomes “broken.”
- Created using
ln -s source_file link_name
. - Can link across different filesystems.
- Shows an arrow (→) in directory listings.
Hard Links
A hard link is a direct reference to the original file’s inode. Unlike soft links, hard links share the same data as the original. Deleting the original file doesn’t affect the hard link, as long as at least one link exists.
- Created using
ln source_file link_name
. - Cannot link directories or span across filesystems.
- All hard links are equal—no “original” vs. “copy.”
 Create a Symbolic link
To create a symbolic link to the file “sample.txt”, use
the following command:
$ ln -s sample.txt symlink_name
symlink_name is the symbolic link to the file. We can replace this with another name. In the example, we have created a symbolic link called ‘slink’ to the file ‘sample.txt’
Notice that the file and the symbolic link have different inode numbers.
We can also create a symbolic link to a directory on Linux. For example,
$ ln -s target_dir link_dir
That’s it.