How to Create and Remove Symbolic Links in Linux
Symbolic links, also known as symlinks or soft links, are special files in Linux that act as pointers or shortcuts to other files or directories. They are extremely useful for simplifying file management, organizing resources, and providing alternative access paths.
In this article, we’ll cover how to create and remove symbolic links in Linux using the command line.
What Is a Symbolic Link?
A symbolic link is like a shortcut in Windows. It doesn’t contain the data of the target file but instead references its path. You can use it to:
Link to files or directories from different locations
Simplify complex paths
Redirect access without duplicating data
How to Create a Symbolic Link
Use the ln command with the -s flag to create a symbolic link:
ln -s /path/to/target /path/to/symlinkExample 1: Link to a File
ln -s /home/user/data.txt /home/user/Desktop/data-link.txtThis creates a symlink named
data-link.txton the Desktop that points to
data.txt.
Example 2: Link to a Directory
ln -s /var/www/html /home/user/websiteNow,
/home/user/websitebehaves like a shortcut to the
/var/www/htmldirectory.
Verify the Symlink
To check if the symbolic link is correctly created, use ls -l:
ls -l /home/user/Desktop/data-link.txtYou should see something like:
lrwxrwxrwx 1 user user 16 May 2 10:00 data-link.txt -> /home/user/data.txtThe l at the beginning indicates a symlink.
How to Remove a Symbolic Link
To remove a symlink, use the rm or unlink command.
Option 1: Using rm
rm /path/to/symlinkOption 2: Using unlink
unlink /path/to/symlink⚠️ Note: Removing a symlink does not delete the original file or directory — only the link itself.
Things to Keep in Mind
If the target of a symlink is deleted or moved, the symlink becomes broken.
Symlinks to directories are not followed by default by commands like rm -r; be careful when automating.
Use readlink -f symlink_name to resolve the full path of a symlink.
Conclusion
Symbolic links in Linux are simple yet powerful tools for organizing and accessing your filesystem more efficiently. With just a couple of commands, you can create and remove symlinks, making it easier to manage files and directories across your system.


