Remove a symlink to a directory

Matthew Scouten

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?

Matthew Scharley
# 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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Remove Symlink to home directory

From Dev

Unlink (remove) directory symlink

From Dev

Is a symlink to a directory a file or a directory?

From Dev

Resolving Directory Symlink in Java

From Dev

Symlink /var/www directory

From Dev

Symlink /var/www directory

From Dev

symlink to already existing directory

From Dev

Switch symlink and directory

From Dev

Safely remove a symlink or hardlink

From Dev

How to check if the directory is symlink in chef

From Dev

SymLink only works in the same directory

From Dev

Go to directory of symlink file target

From Dev

Creating a symlink of directory inside home

From Dev

Symlink all subdirectories in a directory to another directory

From Dev

Automatically symlink directory files into another directory

From Dev

Remove file, but only if it's a symlink

From Dev

Remove mysql symlink as it points to nothing

From Dev

Unable to remove symlink from cygwin

From Dev

Magento 1.8.1: media directory bug if using symlink

From Dev

How to replace a directory with a symlink using ansible?

From Dev

Symlink Copy a Directory Non-recursively

From Dev

Symlink to the latest version formula directory in Homebrew

From Dev

Magento 1.8.1: media directory bug if using symlink

From Dev

Give an application symlink permissions within a directory in Windows

From Dev

Should I include a trailing slash / in a symlink to a directory?

From Dev

Creating a symlink gives cannot overwrite directory error

From Dev

access soft symlink directory's contents in bash

From Dev

"ln -sf" does not overwrite a symlink to a directory

From Dev

Make directory junction (symlink) equivalent to mklink /j

Related Related

HotTag

Archive