Remove Symlink From Ubuntu Linux
Wondering how to remove soft links from your system? Use the rm command. Yes, that's it. Here's how!
In Linux, creating symbolic links is quite easy but what if you want to remove them?
There is an unlink command. But it is not dedicated to links. It is used for removing files as well as link.
In fact, you can use the good old reliable rm command to delete the links.
rm link_name
Let me show how you can use the rm command to remove symbolic links.
How to remove symbolic links in Ubuntu Linux
The rm command is mainly used to remove files from Linux but it can also be used to remove symbolic links.
How? Just follow the given simple syntax:
rm sym_link_or_path_to_symlink
Don't know how to find the symbolic link? You can use the ls or tree command:
tree
As you can see, my symlink is Linuxmint
which is pointing to /home/sagar/Tutorial/LinuxMint.iso
.
So if I were to remove a Linuxmint
symbolic link, then, I'd have to use the following command:
rm Linuxmint
How to remove multiple symbolic links
To remove multiple symlinks, all you have to do is append multiple symbolic filenames:
rm symlink1 symlink2 symlink3
Here, I have two symbolic links: Linuxmint
and Pop-OS
:
So if I want to remove both at once, I'd have to use the following command:
rm Linuxmint Pop-OS
How to remove symbolic link pointing to a Directory
You can create a symlink to a directory so what about removing it? Well, the syntax is the same as you did with files:
rm symlink_to_dir
Remember, never use /
while removing the symbolic link to the directory or it will throw the following error:
So let's say I want to remove the ISO
symlink which is pointing to another directory. Then I will be using the following:
rm ISO
Bonus: Remove hardlink from Ubuntu
You may have created a hard link and want to remove it.
First, it is almost impossible to distinguish between a normal file and a hard link. To do so, you'd have to pay attention to the inode number as it points to the data block so it will be the same as the original file.
Here, I have created a hard link which is pointing to the file in the same directory so I can show the inode numbers easily:
Once you find the symbolic link, you can use the rm command to remove it:
rm Hard-link
And it should remove it!
Hardlinks are much more interesting than you think!
Softlinks are cool but did you know that hard link directly points to the storage block so even if you remove the file, you can still use the hard link to access the data?
There's more to it. And if you're interested, you can refer to our detailed guide:
I hope you will find this guide helpful. And if you have any queries, feel free to ask in the comments.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.