Yes, you can break a symbolic link on Linux by removing the link itself with rm linkname or unlink linkname. These commands do not remove the file or directory the link points to; they remove only the link entry, provided you specify the link rather than its target.
What “breaking” a symbolic link means
A symbolic link, often called a symlink or soft link, is a special filesystem object containing a path to another file or directory. When you access the link, Linux follows that path. Removing the symlink therefore stops that route to the target, but does not normally affect the target itself.
For example, suppose current-report points to /srv/reports/report-2026.txt. Running rm current-report removes current-report. The report remains at its original path, and other links or references to it are unaffected.
“Break” can also mean making a link stop resolving. You can do that by moving or deleting its target, or by changing the target’s path. In that case, the symlink remains, but it becomes a dangling link. The right approach depends on whether you want to remove the link or deliberately leave an invalid one.
Remove a symbolic link safely
For an ordinary symlink to a file or directory, use rm with the link’s name:
rm my-link
You can use unlink as well:
unlink my-link
unlink removes one directory entry and accepts one pathname, so it can make your intent especially clear. Neither command needs a trailing slash. Before removing an unfamiliar link, inspect it:
ls -l my-link
readlink my-link
ls -l typically displays the link and its destination, while readlink prints the stored target path. To see whether a path is a symlink, use a test such as test -L my-link or inspect it with stat.
For a link in the current directory, rm ./my-link can help avoid interpreting a name beginning with a hyphen as an option. In scripts, quote paths that may contain spaces, and use -- before a pathname when supported by the command:
rm -- "$link"
unlink -- "$link"
How to avoid deleting the target
The most important safety rule is to remove the symlink’s pathname, not the pathname it points to. If my-link points to /home/sam/important.txt, run rm my-link, not rm /home/sam/important.txt.
Be particularly careful with recursive commands and trailing slashes. A trailing slash can cause a pathname to be treated as a directory path rather than as the symlink entry you intended to remove. For a directory symlink, use the link name without a trailing slash, and do not add recursive options such as -r unless you have verified exactly what they will act on. If you are uncertain, check the link with ls -ld linkname and remove it with the simple command rm linkname.
Do not assume that every tool handles symlinks the same way. Shell commands, file managers, backup programs, and cleanup scripts can follow links or treat them differently depending on their options. Review a command’s manual page before using it on important data, especially if it combines recursive deletion with paths that may be links.
Make a symlink dangling instead
If your goal is to leave the link in place but make it stop working, change or remove the target rather than the link. For example, if shortcut points to notes.txt, moving notes.txt elsewhere will generally leave shortcut dangling. You can check whether it resolves with:
test -L shortcut && echo "It is a symlink"
test -e shortcut || echo "Its target does not resolve"
These tests answer different questions: -L checks whether the named entry is a symlink, while -e checks whether the path resolves to an existing file. A dangling symlink can satisfy the first test and fail the second. To repair it, remove it and create a new link, or replace it with a link whose target is correct.
Replace a link with a regular file or new link
To replace a symlink, remove it first and then create the intended object. For example:
rm shortcut
printf '%s\n' "Local copy" > shortcut
To point it somewhere else, remove the old link and create a new one with ln -s:
rm shortcut
ln -s /path/to/new-target shortcut
Some versions of ln provide options such as -f to replace an existing destination, but behavior can depend on the command and its options, particularly when directories are involved. Removing and recreating a known symlink explicitly is easier to reason about. If other processes rely on the link, consider whether a brief period when it is absent matters; for critical deployments, use a carefully planned update rather than an improvised replacement.
Common mistakes and troubleshooting
- “Is a directory” or unexpected directory behavior: Check whether the name is a symlink to a directory or an actual directory with
ls -ld name. Use the link name without a trailing slash. - “Permission denied”: Removing a link usually depends on write and search permissions for its parent directory, not on whether you can write to the target. Check the directory permissions and whether the filesystem is mounted read-only.
- “No such file or directory”: The link may be dangling, or you may be in a different directory than expected. Use an absolute path or check your current location with
pwd. - The link still appears after removal: Confirm that you removed the intended entry and refresh the file manager. A different symlink with the same displayed target may exist elsewhere.
- A cleanup command removed more than expected: Stop and inspect the affected paths before running further commands. Recursive deletion and symlink traversal rules vary by tool; do not repeat the command with broader permissions until you understand its behavior.
On Linux, directory permissions and special settings such as the sticky bit can affect whether a user may remove an entry. Using sudo is not a substitute for checking the path: elevated privileges can make a mistaken deletion more damaging.
Related
Frequently Asked Questions
Does deleting a symlink delete the original file?
No. Removing the symlink deletes the link entry only. The target remains unless you separately remove it or another operation affects it.
What is the simplest command to remove a Linux symlink?
Use rm linkname, without a trailing slash. unlink linkname is another suitable choice for removing a single link.
How do I remove a symlink to a directory?
Use rm directory-link without a trailing slash. Verify it is a symlink with ls -ld directory-link; do not use recursive deletion just because its target is a directory.
How can I tell if a symlink is broken?
Run test -L name to check that the entry is a symlink and test -e name to check whether its target resolves. A symlink can exist even when its target does not.
Can I change where a symlink points without deleting it first?
Not by editing the link’s stored path in place with a basic shell command. A common method is to remove the old symlink and create a new one with ln -s; take care if software depends on the link during the change.