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.
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
Use the ln command with the -s flag to create a symbolic link:
This creates a symlink named data-link.txt
on the Desktop that points to data.txt
.
Now, /home/user/website
behaves like a shortcut to the /var/www/html
directory.
To check if the symbolic link is correctly created, use ls -l:
You should see something like:
The l at the beginning indicates a symlink.
To remove a symlink, use the rm or unlink command.
⚠️ Note: Removing a symlink does not delete the original file or directory — only the link itself.
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.
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.