ln question
ALeine
aleine at austrosearch.net
Fri Feb 18 02:21:13 PST 2005
Jumbler_Chi at 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 at freebsd.org in the future.
ALeine
___________________________________________________________________
WebMail FREE http://mail.austrosearch.net
More information about the freebsd-hackers
mailing list