How to Create and Remove Symbolic Links in Linux

Popular:
LEVEL UP YOUR SERVER SETUP! APPLY AVA AND LAUNCH WITH A 15% DISCOUNT
USE PROMO:

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:

ln -s /path/to/target /path/to/symlink
ln -s /home/user/data.txt /home/user/Desktop/data-link.txt

This creates a symlink named

data-link.txt

on the Desktop that points to

data.txt

.

ln -s /var/www/html /home/user/website

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:

ls -l /home/user/Desktop/data-link.txt

You should see something like:

lrwxrwxrwx 1 user user 16 May 2 10:00 data-link.txt -> /home/user/data.txt

The l at the beginning indicates a symlink.

To remove a symlink, use the rm or unlink command.

Option 1: Using rm

rm /path/to/symlink
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.