A symbolic link also called a symlink or soft link is a file that points to another file or directory. This works in the same way as a Windows shortcut. Soft links, which are comparable to shortcuts and can lead to any file or directory in any file system, are the most common type of symlink.
There are two types of links in Linux/UNIX systems:
These are the low-level connections. It represents the physical location of a file and links several filenames to the same Inode. When a hard link is made for a file, it points to the original file’s Inode in the disk space, implying that no new Inode is produced. Hard links aren’t used to construct directories, and they can’t transcend filesystem borders. Hard links are not affected when the source file is removed or transferred.
Soft links are common. It represents the file’s virtual or abstract location. It’s similar to how Windows shortcuts work. A soft link does not contain any of the connected file’s information or content; instead, it contains a pointer to the linked file’s location. In other words, a new file is generated with a new Inode and a pointer to the original file’s Inode location.
Create Symbolic Links
- To create a symbolic link to a given file, open your terminal and type:
ln -s source_file symbolic_link
Replace source_file with the name of the existing file for which you want to create the symbolic link and symbolic_link with the name of the symbolic link.
We are creating a symbolic link named my_link.txt to a file named my_file.txt:
ln -s my_file.txt my_link.txt
To verify that the symlink was successfully created, use the ls command:
ls -l my_link.txt
To delete/remove symbolic links use either the unlink or rm command.