Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Jul 2000 01:35:03 +0200
From:      Siegbert Baude <siegbert.baude@gmx.de>
To:        Mike Meyer <mwm@mired.org>, "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: Replacing symbolic link to directory
Message-ID:  <39690C27.C180DC02@gmx.de>
References:  <bulk.7196.20000708094653@hub.freebsd.org> <14695.48116.939565.809592@guru.mired.org>

next in thread | previous in thread | raw e-mail | index | archive | help
> That's the clue as to what's going on.  It's telling you it created a
> link called "d3/d2" to the directory d2.  When the target of ln is a
> directory - or a link to one - the target file is changed to be a file
> with the basename of the original file.

Is there a way to do what I wanted to achieve: Replace an already
existing symbolic link to a directory with one command?

For general discussion:
The strength of UNIX is to consequently apply simple principles. So
compared with the behaviour of rm and ls (see examples below), I would
expect ln to make a difference between:
ln -fs d1 d2 -> replacing the existing symbolic link d2
ln -fs d1 d2/ -> replacing the existing symbolic link d2/d1 

This is maybe a question about UNIX philosophy or Stone Age design
decisions (I just tried and the behaviour of ln is exactly the same with
GNU ln on Solaris and Linux, and within BeOS), but there actually is a
difference between a symbolic link to a directory and a directory itself
(which for my taste is denied by nowadays behaviour of ln, but I'm no
guru of Unix history and the answers, why certain decisions happened to
be like they are). rm and ls for example behave different if applied to
a symbolic link:

Example 1:

bash-2.03$ mkdir d1
bash-2.03$ ln -s d1 d2
bash-2.03$ ls -l
total 1
drwxr-xr-x  2 foo  bar  512 10 Jul 01:00 d1/
lrwxr-xr-x  1 foo  bar    2 10 Jul 01:00 d2@ -> d1
bash-2.03$ rm d2/
rm: d2/: is a directory
bash-2.03$ rm d2
bash-2.03$ ls -l
total 1
drwxr-xr-x  2 foo  bar  512 10 Jul 01:00 d1/
bash-2.03$

Example 2:
bash-2.03$ mkdir d1
bash-2.03$ ln -s d1 d2
bash-2.03$ touch d2/f2
bash-2.03$ ls d2
d2@
bash-2.03$ ls d2/
f2
bash-2.03$

Example 3:
bash-2.03$ mkdir d1
bash-2.03$ ln -s d1 d2
bash-2.03$ ls -l
total 1
drwxr-xr-x  2 foo  bar  512 10 Jul 01:26 d1/
lrwxr-xr-x  1 foo  bar    2 10 Jul 01:26 d2@ -> d1
bash-2.03$ unlink d2/
unlink: d2/: is a directory
bash-2.03$ unlink d2
bash-2.03$ ls -l
total 1
drwxr-xr-x  2 coocoo  coocoo  512 10 Jul 01:26 d1/
bash-2.03$
Excerpt from man unlink (man rm):
     When the utility is called as unlink, only one argument, which must
not
     be a directory, may be supplied.  No options may be supplied in
this sim-
     ple mode of operation, which performs an unlink(2) operation on the
     passed argument.
 
So d2 is not treated as directory, but rather as symbolic link.

Summary: if d2 is a symbolic link, d2/ refers to the referenced
directory whereas d2 (without slash) refers to the symbolic link itself.

Shouldn't this be the same for ln?

Ciao
Siegbert


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




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