I have a symlink to an important directory. I want to get rid of that symlink, while keeping the directory behind it.
I tried rm
and get back rm: cannot remove 'foo'
.
I tried rmdir
and got back rmdir: failed to remove 'foo': Directory not empty
I then progressed through rm -f
, rm -rf
and sudo rm -rf
Then I went to find my back-ups.
Is there a way to get rid of the symlink with out throwing away the baby with the bathwater?
To remove a symbolic link, use either the rm or unlink command followed by the name of the symlink as an argument. When removing a symbolic link that points to a directory do not append a trailing slash to the symlink name.
Remove a Symbolic Link using the rm command You can also use the -i flag with the rm command to prompt for confirmation. After that, you can use the ls -l command to confirm if the symlink has been removed. That is all there is to it!
The symbolic link does not contain any data, but you can perform all operations on the symbolic link file. Removing a symbolic link does not delete the original file, but deleting a file makes the symlink a dangling link.
# this works: rm foo # versus this, which doesn't: rm foo/
Basically, you need to tell it to delete a file, not delete a directory. I believe the difference between rm
and rmdir
exists because of differences in the way the C library treats each.
At any rate, the first should work, while the second should complain about foo being a directory.
If it doesn't work as above, then check your permissions. You need write permission to the containing directory to remove files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With