Home > bash > ln – symbolic links

ln – symbolic links

Problem:
I keep getting this wrong. I installed xmind and needed to add it to my PATH. What I decided to do was add a symbolic link to xmind in /usr/local/bin which was in my PATH. This is a two second job that took 5 mins coz I keep on fudging up ln -s by interchanging LINKNAME and TARGET :-).

RTFM:
From info coreutils ‘ln invocation’

`ln’ makes links between files. By default, it makes hard links; with
the `-s’ option, it makes symbolic (or “soft”) links. Synopses:

ln [OPTION]… [-T] TARGET LINKNAME
ln [OPTION]… TARGET
ln [OPTION]… TARGET… DIRECTORY
ln [OPTION]… -t DIRECTORY TARGET…

* If two file names are given, `ln’ creates a link to the first file
from the second.

TARGET = /usr/local/xmind/xmind
LINKNAME = /usr/local/bin/xmind

Which results in
root@computer#ln -s /usr/local/xmind/xmind /usr/local/bin/xmind

Advertisements
Categories: bash Tags: ,
  1. September 3, 2012 at 10:56 pm

    It happened to me too, until I noticed that:
    ln -s /etc/somefile
    would create a symlink to /etc/somefile, that is, it is not necessary to specify the LINKNAME because it will default to the same name as the TARGET.
    So I saw it like: the LINKNAME is only necesary to give if you intend to use a different name other than TARGET has.
    So, cuting it short: only use TARGET and LINKNAME if you want your new symlink to have a different name than TARGET. If you just want you new symlink to have the same name as TARGET, then don’t put LINKNAME at all

    So after a while of seeing it and using it like this, it gets obvious, that the first filename supplied must be link-source, and the second filename suplied (if given) must be the new symlink name

    Hope I explained it right… it was not easy…

    • September 4, 2012 at 4:42 am

      Thank you for your explanation. It has helped.

  1. No trackbacks yet.

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