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

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

23 thoughts on “How to create and remove a soft link, symlink or symbolic link

  1. Thanks “Whose name” for the heads up.

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

    hope it makes sense :)

  2. 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.

  3. 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.

  4. 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.

  5. I was trying to get apache2 to identify a folder at a location. Since by default apache looks under /var/www/ for what to open, I wanted to create a symbolic link there to point to the folder where I wanted my browser to open a .php file. So when I searched for how to create a symbolic link, I found your great post on it. :) Thanks a lot! :)

  6. If some one wishes expert view concerning running a blog afterward i recommend
    him/her to pay a visit this blog, Keep up the fastidious work.

  7. Thanks a lot!!! This truly saved my time!!! I only wish this to take the top position on Google search, when people keep typing how to remove a symbolic link, how to remove a soft link, rm doesn’t work on soft links, rm doesn’t work on symbolic link, rm: cannot remove `symbolic link/': Is a directory and such things.

  8. iam getting permission denied when i do soft linking, the owner of the file different. is there any way we can do forcefully.

    • Hi srikanth, That woud be dangerous if any one could delete files of others. You’ll need to change to that user or become root, and then change the permissions/owner or group

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s