From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 18 10:38:57 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A081816A4CE for ; Fri, 18 Feb 2005 10:38:57 +0000 (GMT) Received: from pop-a065c05.pas.sa.earthlink.net (pop-a065c05.pas.sa.earthlink.net [207.217.121.183]) by mx1.FreeBSD.org (Postfix) with ESMTP id 55B3E43D2F for ; Fri, 18 Feb 2005 10:38:57 +0000 (GMT) (envelope-from andrei@kableu.com) Received: from h-68-164-241-175.snvacaid.dynamic.covad.net ([68.164.241.175] helo=mail.kableu.com) by pop-a065c05.pas.sa.earthlink.net with esmtp (Exim 3.33 #1) id 1D25XE-0001XH-00; Fri, 18 Feb 2005 02:38:56 -0800 Received: from warrior.kableu.com (warrior.kableu.com [192.168.0.1]) by mail.kableu.com (Postfix) with ESMTP id 15F72C0C7; Fri, 18 Feb 2005 02:38:56 -0800 (PST) Received: by warrior.kableu.com (Postfix, from userid 1001) id BECEF11444; Fri, 18 Feb 2005 02:38:55 -0800 (PST) Date: Fri, 18 Feb 2005 02:38:55 -0800 From: Andrew Konstantinov To: Jumbler_Chi@mobitai.com.tw Message-ID: <20050218103855.GA1472@warrior.kableu.com> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DocE+STaALJfprDB" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i cc: freebsd-hackers@freebsd.org Subject: Re: ln question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Feb 2005 10:38:57 -0000 --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--