How to Remove a Symbolic Link (Symlink) in Linux

A symbolic link (symlink) is a special type of file that points to another file or directory. It works like a shortcut, letting you organize and access files more efficiently. You can create symlinks with the ln command
, and if you are unsure which link type to use, see hard links vs symbolic links
.
This guide explains how to remove symbolic links in Linux using the rm, unlink, and find commands.
Quick Reference
For a printable quick reference, see the ln cheatsheet .
| Task | Command |
|---|---|
| Remove a symlink | rm symlink_name |
| Remove with confirmation | rm -i symlink_name |
| Remove multiple symlinks | rm symlink1 symlink2 |
| Remove a symlink (unlink) | unlink symlink_name |
| Find broken symlinks | find /path -xtype l |
| Find broken symlinks (portable) | find -L /path -type l |
| Delete broken symlinks | find /path -xtype l -delete |
| Remove every symlink in a tree | find /path -type l -delete |
Before You Begin
To remove a symlink, you must have write permissions on the directory containing it. Otherwise, the command returns a permission-related error.
When you remove a symlink, the file or directory it points to is not affected. Only the link itself is deleted.
Use the ls -l
command to check whether a file is a symbolic link and see where it points:
ls -l /usr/bin/python3lrwxrwxrwx 1 root root 10 Aug 18 2024 /usr/bin/python3 -> python3.12The first character l indicates that the file is a symlink. The -> symbol shows the target file.
Remove Symbolic Links with rm
The rm
command removes files and directories.
To delete a symlink, invoke rm followed by the symbolic link name:
rm symlink_nameOn success, the command produces no output and exits with zero.
You can remove more than one symbolic link at once by passing multiple names separated by spaces:
rm symlink1 symlink2To get a confirmation prompt before removing the symlink, use the -i option:
rm -i symlink_nameType y and press Enter to confirm:
rm: remove symbolic link 'symlink_name'?Avoid the Trailing Slash
If the symbolic link points to a directory, do not append a trailing / to the symlink name. Otherwise, rm treats it as a directory and returns an error:
rm symlink_to_dir/rm: cannot remove 'symlink_to_dir/': Is a directoryThis happens because, when used without the -d or -r option, rm cannot remove directories.
The trailing slash turns dangerous as soon as you add -r or -f. A pathname that ends in / forces the name before it to resolve to a directory, so rm follows the link and works on the target instead of on the link:
rm -rf symlink_to_dir/That command deletes the files inside the target directory and leaves the symlink in place, now dangling. Dropping the slash makes rm -rf symlink_to_dir safe, since it then removes only the link, but the habit worth keeping is simpler: never type a trailing slash after a symlink name.
Remove Symbolic Links with unlink
The unlink
command deletes a single file. Unlike rm, it accepts only one argument.
To delete a symbolic link with unlink, pass the symlink name as an argument:
unlink symlink_nameIf the command succeeds, it produces no output.
Do not append a trailing / to the symlink name because unlink cannot remove directories.
Find and Delete Broken Symbolic Links
If you delete or move the target file, the symbolic link becomes dangling (broken) and no longer works.
To find all broken symbolic links under a given directory, run the following command:
find /path/to/directory -xtype l/path/to/directory/symlink1
/path/to/directory/subdir/symlink2The -xtype l test matches symbolic links whose targets do not exist.
The -xtype test belongs to GNU find, which is what Ubuntu, Debian, Fedora, and RHEL ship. On systems with BSD find, such as macOS, use the -L option instead. It tells find to follow symbolic links, so a working link is reported as whatever it points at, and only the broken ones are still left matching -type l:
find -L /path/to/directory -type lGNU find accepts this form too, which makes it the safer choice for a script that has to run on more than one system.
To limit the search to the current directory level without descending into subdirectories, pass the -maxdepth 1 option to find
:
find /path/to/directory -maxdepth 1 -xtype l/path/to/directory/symlink1Once you find the broken symlinks, you can remove them manually with rm or unlink, or use the -delete option of find to remove them all at once:
find /path/to/directory -xtype l -deleteRemove All Symbolic Links in a Directory
Sometimes you need to clear every symlink under a directory, not only the broken ones. Drop the x from the test so that find matches links whether or not their targets still exist, and list them before removing anything:
find /path/to/directory -type l/path/to/directory/symlink1
/path/to/directory/config_link
/path/to/directory/subdir/symlink2Once the list matches what you expect, add -delete to the same command:
find /path/to/directory -type l -deleteThe files and directories those links pointed to are left alone. -delete removes the directory entry for each link without following it, so only the links disappear.
Troubleshooting
rm: cannot remove ‘symlink/’: Is a directory
You appended a trailing / to a symlink that points to a directory. Drop the slash: rm symlink. Never use rm -rf symlink/ because it can follow the link and remove the target directory contents.
rm: cannot remove ‘symlink’: No such file or directory
The symlink does not exist at that path, or you are in the wrong directory. Verify with ls -l symlink and use an absolute path if needed.
unlink: cannot unlink ‘symlink’: Operation not permitted
You do not have write permission on the parent directory. Check ownership with ls -ld . and rerun with sudo only if the parent is system-owned.
FAQ
Does removing a symlink delete the original file?
No. Removing a symlink only deletes the link itself. The original file or directory it points to remains intact.
How do I check if a file is a symlink?
Run ls -l filename. If the first character of the permissions string is l, the file is a symbolic link. The output also shows the target after a -> arrow.
What happens to a symlink when the target is deleted?
The symlink becomes a dangling (broken) link. It still exists on disk, but any attempt to access it will fail with a “No such file or directory” error. Use find /path -xtype l to locate broken symlinks.
What is the difference between rm and unlink for removing symlinks?
Both commands remove symlinks the same way. The main difference is that unlink only accepts a single argument, while rm can remove multiple files at once and supports options like -i for interactive confirmation.
Conclusion
To remove a symbolic link, use rm or unlink followed by the symlink name. Do not append a trailing slash when removing a symlink that points to a directory.
Use find /path -xtype l when you need to clean up broken links after moving or deleting target files.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page