How is a symlink removed from a home directory. I accidentally created a symlink for my home directory, but am worried that deletion will have unintended consequences on my real home directory.


If you jave just created a symlink you can simply rm it. Without the -r and -f it will not delete directories:

[me@localhost test]$ ln -s ~ alink
[me@localhost test]$ ls -l
total 4
lrwxrwxrwx 1 me me 11 Sep 15 02:54 alink -> /home/me
[me@localhost test]$ rm alink
[me@localhost test]$ ls -l
total 0
[me@localhost test]$ rm ~
rm: cannot remove '/home/me': Is a directory

If you have created a link/file/directory called ~ then you can run rm -- '~' to remove it, if it is a directory rm -rf -- '~'.

-- Tells rm that any following arguments are not to be interpreted but are all filenames, the single quotes '~' tell bash to not interpret and expand the ~.

However this is very risky to do. A safer way is to move the file first. That way if you mess up you can just move it back. This can be done the same way with mv -- '~' newloaction then rm newlocation once you are happy your home is still intact.

[me@localhost test]$ ln -s ~ -- '~'
[me@localhost test]$ ls -l
total 4
lrwxrwxrwx 1 me me   11 Sep 15 02:51 '~' -> /home/me
[me@localhost test]$ rm -- '~'
[me@localhost test]$ ls -l
total 0

Removing a symbolic link has no effect on the link-target (but you might need a link for itself, e.g., if that link is from a preferred location to a place where your home directory was moved).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.