How to Remove Symbolic Links in Ubuntu Linux
A symbolic link (symlink) in Ubuntu is a shortcut that points to a file or folder somewhere else on the system. Removing a symlink deletes only the pointer. The original file or folder stays exactly where it was.
You can clear out broken or unwanted symlinks on Ubuntu 22.04 and other recent versions with the terminal command rm or unlink. Both remove the link and leave your data alone. A link usually becomes broken when the file or folder it pointed to has been moved or deleted. This guide covers opening the terminal, finding the link, confirming its name, and deleting it with either command.
To remove a symbolic link on Ubuntu, open the terminal with Ctrl+Alt+T, go to the folder that holds the link with cd, and run rm followed by the link name, such as rm symlink_name. Only the pointer is deleted; the original file or folder stays where it was. You can also use unlink symlink_name, which does the same thing.
Open the terminal
Press Ctrl+Alt+T to open the terminal. A terminal window should appear with a prompt waiting for input. If the shortcut does nothing, open the Activities overview, type Terminal in the search box and click the app.
- Press Ctrl+Alt+T on your keyboard. This keyboard shortcut launches the terminal window. You don’t need administrator rights just to open it.
Change to the symbolic link directory
To remove a symbolic link in Ubuntu, first move into the folder where the shortcut lives. Type cd followed by the folder path in the terminal and press Enter. This puts your session in the right folder, so you can work with the link by its short name and avoid touching other files by accident.
If you see “No such file or directory”, check the path for typos. Pressing Tab while you type completes folder names for you. If a folder name contains spaces, put the whole path in quotes.
Substitute ~/Downloads with the actual path to the directory containing your symbolic link.
cd ~/Downloads
Remember to replace ~/Downloads with the actual path to the directory containing your symbolic link. A path that starts with / is absolute and works from anywhere. A path without it is relative to the folder you are in now.
Identify the symbolic link
Before you delete anything, check the exact name of the shortcut. Type ls -l in the terminal to get a detailed list of everything in the current folder. Symlinks are easy to spot because their line starts with the letter l. Each one also shows the file or folder it points to, which confirms you have the right link.
ls -l
Look for entries starting with lrwx, indicating they function as symbolic links. Regular files and folders start with a different character, so they are easy to tell apart.
ls -l /usr/bin/python
The output also displays where the link points. The link name comes first, then an arrow, then the target. Make a note of the link name exactly as it appears, including capital letters, because Linux file names are case-sensitive. If the target no longer exists, the link is broken, and it is safe to remove.
lrwxrwxrwx 1 root root 9 Apr 16 2023 /usr/bin/python -> python3
Remove the symbolic link
The first way to remove a symbolic link in Ubuntu is the rm command. It deletes the shortcut and leaves the original files alone. Type rm followed by the name of your link and press Enter. The link is removed straight away, with no Trash and no undo. The target file or folder stays safe and intact.
rm symlink_name
symlink_name with the actual name of your symbolic link.This command removes the symlink itself, preserving the target file or directory. If the link points to a folder, type the name without a slash at the end. A trailing slash makes the shell treat it as the folder itself, and the command will fail with an error. If you get "Permission denied", you don't have write access to the folder that holds the link. In that case, run the same command with sudo in front.
Appending the -i option triggers a prompt before removing the symlink. The terminal asks whether you really want to remove the link. Type y and press Enter to confirm, or press Enter alone to cancel. This is a good habit when you are working in a folder with many similar names:
rm -i symlink_name
Remove symbolic links with unlink
The second way to remove a symbolic link in Ubuntu is the unlink command, which deletes one shortcut at a time. Type unlink followed by the name of your link and press Enter. It does only this one job, so it is harder to misuse than rm. It removes the link and does not touch your original data.
The unlink command focuses on handling one symlink at a time. It accepts a single name and has no options, so you can't use it to delete several links in one go.
Run the unlink command followed by the symlink name as an argument to delete a symbolic link. As with rm, leave off any trailing slash. If the command prints nothing, it worked:
unlink symlink_name
That completes the process. To check, run ls -l again in the same folder. The link should no longer be listed, and the original file or folder should still be in its own location. If you removed a link by mistake, you can create it again, since the target was never touched.
Removing symbolic links helps reduce clutter and avoid confusion when accessing files and directories. Use either the rm or unlink command depending on your setup. Use rm if you want the confirmation prompt, and unlink if you want a command that handles only a single link.
- Removing symbolic links in Ubuntu Linux is essential for maintaining a clean and efficient file system.
- Properly managing symbolic links helps reduce clutter, improve system performance, and avoid confusion when accessing files and directories.
- The
rmcommand or theunlinkcommand can remove symbolic links based on your specific requirements. - Always exercise caution when removing symbolic links to ensure you do not inadvertently delete essential files or directories. Run ls -l first and confirm the line starts with l.
- Feel free to share your feedback or tips in the comments section below.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!