Date: Fri, 18 Feb 2005 02:38:55 -0800 From: Andrew Konstantinov <andrei@kableu.com> To: Jumbler_Chi@mobitai.com.tw Cc: freebsd-hackers@freebsd.org Subject: Re: ln question Message-ID: <20050218103855.GA1472@warrior.kableu.com> In-Reply-To: <OF9B766A93.00A23F1F-ON48256FAC.00312185@mobitai.com.tw> References: <OF9B766A93.00A23F1F-ON48256FAC.00312185@mobitai.com.tw>
next in thread | previous in thread | raw e-mail | index | archive | help
--DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 18, 2005 at 05:17:07PM +0800, Jumbler_Chi@mobitai.com.tw wrote: > Hi hackers ! >=20 > I have one strange thing about 'ln' command. > my box is 5.2R. > I built some directory on $HOME , such as $HOME/a/b > I want to create a symbolic link for 'b' under top directory , $HOME. The confusion is caused by the fact that you assume that whenever you creat= e a soft link, ln will translate given source_file path into a valid path relat= ive to the location of the newly created link, which is not true. > so , I typed some command as >=20 > $ mkdir $HOME/a > $ mkdir $HOME/a/b >=20 > $ 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 In this case you tell "ln" to create a link to "b" in the parent directory.= You assume that "ln" will be smart enough to take into consideration that your reference is in context of current working directory "a", and will change it appropriately, which is not true. All it does is 1) go to parent 2) create a symlink file "b" which points to file named "b", which actually is an infin= ite cycle, because the only entry in your parent directory with name "b" is "b" itself, which is a symlink to file named "b" relative to your $HOME. What you've done is equivalent to: > ln -s test test > ls -la test lrwx------ 1 andrei andrei 4 Feb 18 02:37 test -> test > file test test: broken symbolic link to `test' >=20 > 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 >=20 > $ mkdir $HOME/a > $ mkdir $HOME/a/b > $ cd $HOME > $ ln -s a/b . > $ cd $HOME/b This is different. Now, you tell ln that it should creat a symlink in curre= nt working directory with the name "b" which points to file named "a/b" and th= at's perfectly fine because your $HOME (current working directory) directory contains the actual file "a/b". Hope this helps, Andrew --DocE+STaALJfprDB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (FreeBSD) iD8DBQFCFcW/g+6MtxSjexcRAr0iAJ4gpDsWO78SlPHRxIpCYiD69P6hbACcCeYC H5HplsVxkp9YYcmGykCE31Q= =MJ9v -----END PGP SIGNATURE----- --DocE+STaALJfprDB--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050218103855.GA1472>