From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 18 10:21:13 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 701C116A4CE for ; Fri, 18 Feb 2005 10:21:13 +0000 (GMT) Received: from marlena.vvi.at (marlena.vvi.at [208.252.225.59]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B19643D3F for ; Fri, 18 Feb 2005 10:21:13 +0000 (GMT) (envelope-from www@marlena.vvi.at) Received: from marlena.vvi.at (localhost.marlena.vvi.at [127.0.0.1]) by marlena.vvi.at (8.12.10/8.12.9) with ESMTP id j1HEPhoH068945; Thu, 17 Feb 2005 06:25:45 -0800 (PST) (envelope-from www@marlena.vvi.at) Received: (from www@localhost) by marlena.vvi.at (8.12.10/8.12.10/Submit) id j1HEPcT1068944; Thu, 17 Feb 2005 06:25:38 -0800 (PST) (envelope-from www) Date: Thu, 17 Feb 2005 06:25:38 -0800 (PST) Message-Id: <200502171425.j1HEPcT1068944@marlena.vvi.at> To: Jumbler_Chi@mobitai.com.tw From: "ALeine" 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:21:13 -0000 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