How to create and remove a soft link, symlink or symbolic link

Posted on November 15, 2007. Filed under: console, gnu, linux, open source | Tags: , , , , , , , |

A soft link, or more common, a symlink, is link a shortcut to the targeted file or directory. So when is removed the original target stays present. This is the opposite of a hard link which is a reference to the target and so, if the hard link is removed, so is the target.

A symlink can be created like:

ln -s /path/ linkname

from the ln man pages:

ln [OPTION]… [-T] TARGET LINK_NAME (1st form)

-s, –symbolic
make symbolic links instead of hard links

to remove a symlink

rm linkname

What is important here is to note that the command doesn’t have the trailing slash

$ rm linkname/

will output the error:
rm: cannot remove `linkname/': Is a directory

$ rmdir linkname/
will output:
rmdir: linkname/: Not a directory

So it’s a directory or not?? i guess different tools have different ways of looking at this. Isn’t GNU/Linux great?! :D

Make a Comment

Make a Comment: ( 11 so far )

blockquote and a tags work here.

11 Responses to “How to create and remove a soft link, symlink or symbolic link”

RSS Feed for The GNU of Life, the Universe and Everything Comments RSS Feed

[...] Nerdica wrote an interesting post today onHere’s a quick excerptA soft link, or more common, a symlink, is link a shortcut to the targeted file or directory. So when is removed the original target stays present. This is the opposite of a hard link which is a reference to the target and so, if the hard link is removed, so is the target. A symlink can be created like: ln -s /path/ linkname from the ln man pages: ln [OPTION]… [-T] TARGET LINK_NAME (1st form) -s, –symbolic make symbolic links instead of hard links [...]

[...] see in this post how to create a symlink so, everytime you change this file you don’t need to copy it to the [...]

What is important here is to note that i doesn’t have the trailing slash

what is i?

Thanks “Whose name” for the heads up.

“i” should be “it” which is “the command”.

hope it makes sense :)

[...] under your dropbox folder. Solution, symbolic links. SymbolicLinker is a cool plugin for creating symbolic links using Finder from the right click menu. Place the links in your Dropbox folder to backup the [...]

hey buddy use unlink instead of rm command

unlink linkname

Badi Ul Zaman

MCSE,RHCE,JNCIS

bnhashmi@yahoo.com

hei there buddy!

thanks for the tip but in most GNU Linux Systems rm uses unlink to remove files so unlink will run into the same problems.

Your problem is that you’re using tab completion, which automatically appends a ‘/’ to the end of your symlink. Syntactically, this appears to be a directory to rm. If you simply say “rm linkname” (without any trailing slash), the command will work.

Thank you very much! I was having an awful job trying to remove the the symlink and it was as simple as getting rid of the trailing slash. You’ve saved me some hair-pulling. Thanks again.

# this works
rm linkname
# versus
rm linkname/

Basically you need to tell it its a file not a dir (/)

try “rm linkname” instead of “rm linkname/”


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...