The GNU of Life, the Universe and Everything

November 15, 2007

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

Filed under: console, linux — Tags: , , , , , , , — Pedro Carvalho @ 10:42 pm

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

About these ads

20 Comments »

  1. [...] 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 [...]

    Pingback by Linux Code and More » Blog Archive » How to create and remove a soft link, symlink or symbolic link — November 15, 2007 @ 10:47 pm

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

    Pingback by How to start a new X server with Quake wars to work as a minimizer « The GNU of Life, the Universe and Everything — November 15, 2007 @ 11:10 pm

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

    what is i?

    Comment by Whose name — April 22, 2008 @ 12:29 pm

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

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

    hope it makes sense :)

    Comment by Pedro Carvalho — April 22, 2008 @ 1:15 pm

  5. [...] 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 [...]

    Pingback by Dropbox with symbolic links in finder | digiculturetravelexpatasia — September 15, 2008 @ 7:31 am

  6. hey buddy use unlink instead of rm command

    unlink linkname

    Badi Ul Zaman

    MCSE,RHCE,JNCIS

    bnhashmi@yahoo.com

    Comment by Badi Ul Zaman — December 4, 2008 @ 8:31 am

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

    Comment by Pedro Carvalho — December 4, 2008 @ 8:56 am

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

    Comment by Brian Stempin — April 10, 2009 @ 8:41 pm

    • Thank you so much

      Comment by kalpana — March 13, 2012 @ 7:59 pm

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

    Comment by sislii — May 20, 2009 @ 1:14 am

  10. # this works
    rm linkname
    # versus
    rm linkname/

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

    Comment by Brian — June 17, 2009 @ 9:40 pm

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

    Comment by a2j — July 5, 2009 @ 2:37 am

  12. hai

    Comment by ghg — February 3, 2011 @ 11:11 am

  13. 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! :)

    Comment by Haris Ibrahim K. V. — September 14, 2011 @ 3:18 pm

    • :) Well done!

      Comment by Pedro Carvalho — October 23, 2011 @ 1:36 am

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

    Comment by Anonymous — May 16, 2013 @ 12:02 am

  15. wonderful post. saved me lot of time :)

    Comment by Murali — June 3, 2013 @ 6:22 pm

  16. I love it when individuals come together and share ideas.

    Great website, continue tthe good work!

    Comment by term papers — September 30, 2013 @ 3:55 pm

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

    Comment by Chathura Asanga Kulasinghe — April 17, 2014 @ 2:44 pm

    • Thanks for the nice comment! Glad it helped you!

      Comment by Pedro Carvalho — April 17, 2014 @ 3:37 pm


RSS feed for comments on this post. TrackBack URI

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

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: