Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Feb 2005 06:25:38 -0800 (PST)
From:      "ALeine" <aleine@austrosearch.net>
To:        Jumbler_Chi@mobitai.com.tw
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: ln question 
Message-ID:  <200502171425.j1HEPcT1068944@marlena.vvi.at>

next in thread | raw e-mail | index | archive | help
Jumbler_Chi@mobitai.com.tw wrote: 

> I have one strange thing about 'ln' command.
> my box is 5.2R.

This is not strange, it works exactly as expected, but you do not
seem to understand how ln works. Read on for the explanation...

> I built some directory on $HOME , such as $HOME/a/b
> I want to create  a symbolic link for 'b'  under top directory ,
> $HOME.
> 
> so , I typed some command as
> 
> $ mkdir $HOME/a
> $ mkdir $HOME/a/b
> 
> $ cd $HOME/a
> $ ln -s b ../
> $ cd $HOME/b
> cd: can't cd to /home/matrix/b
> $ file $HOME/b
> b: broken symbolic link to b

You created a symbolic link $HOME/b which is pointing to b. Since
it is not pointing to an absolute path ($HOME/b -> /home/you/a/b),
but rather a relative one ($HOME/b -> b), the full path is obtained
by using the directory which contains the symbolic link as the base
directory, meaning your symbolic link is pointing to itself. If you
used a shell like tcsh you would see something like this when trying
to cd due to the recursion caused by the self reference:

b: Too many levels of symbolic links.

> but  when I also created another symbolic link as following again
> , it is
> ok.  why is it broken symbolic link?!
> $ rm $HOME/b
> $ rmdir $HOME/a/b
> $ rmdir $HOME/a
> 
> $ mkdir $HOME/a
> $ mkdir $HOME/a/b
> $ cd $HOME
> $ ln -s a/b .
> $ cd $HOME/b

You created a symbolic link $HOME/b which points to a/b. Because it
is pointing to a relative path, again the directory containing the
symbolic link is used as the base directory, meaning your symbolic
link is pointing to $HOME/a/b, which is what you want.

Reading man 1 ln and using ls -al to check where your symbolic links
are pointing would have made that clear. You may want to post such
questions to freebsd-questions@freebsd.org in the future.

ALeine
___________________________________________________________________
WebMail FREE http://mail.austrosearch.net 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200502171425.j1HEPcT1068944>