How to Remove a Symbolic Link (Symlink) in Linux

By 

Updated on

6 min read

Remove Symbolic Links 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 .

TaskCommand
Remove a symlinkrm symlink_name
Remove with confirmationrm -i symlink_name
Remove multiple symlinksrm symlink1 symlink2
Remove a symlink (unlink)unlink symlink_name
Find broken symlinksfind /path -xtype l
Find broken symlinks (portable)find -L /path -type l
Delete broken symlinksfind /path -xtype l -delete
Remove every symlink in a treefind /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:

Terminal
ls -l /usr/bin/python3
output
lrwxrwxrwx 1 root root 10 Aug 18  2024 /usr/bin/python3 -> python3.12

The first character l indicates that the file is a symlink. The -> symbol shows the target file.

The rm command removes files and directories.

To delete a symlink, invoke rm followed by the symbolic link name:

Terminal
rm symlink_name

On 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:

Terminal
rm symlink1 symlink2

To get a confirmation prompt before removing the symlink, use the -i option:

Terminal
rm -i symlink_name

Type y and press Enter to confirm:

output
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:

Terminal
rm symlink_to_dir/
output
rm: cannot remove 'symlink_to_dir/': Is a directory

This 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:

Terminal
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.

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:

Terminal
unlink symlink_name

If the command succeeds, it produces no output.

Do not append a trailing / to the symlink name because unlink cannot remove directories.

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:

Terminal
find /path/to/directory -xtype l
output
/path/to/directory/symlink1
/path/to/directory/subdir/symlink2

The -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:

Terminal
find -L /path/to/directory -type l

GNU 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 :

Terminal
find /path/to/directory -maxdepth 1 -xtype l
output
/path/to/directory/symlink1

Once 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:

Terminal
find /path/to/directory -xtype l -delete

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:

Terminal
find /path/to/directory -type l
output
/path/to/directory/symlink1
/path/to/directory/config_link
/path/to/directory/subdir/symlink2

Once the list matches what you expect, add -delete to the same command:

Terminal
find /path/to/directory -type l -delete

The 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.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

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