On Fri, Feb 18, 2005 at 05:17:07PM +0800, [EMAIL PROTECTED] wrote: > Hi hackers ! > > 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 create a soft link, ln will translate given source_file path into a valid path relative to the location of the newly created link, which is not true. > 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 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 infinite 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' > > 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 This is different. Now, you tell ln that it should creat a symlink in current working directory with the name "b" which points to file named "a/b" and that's perfectly fine because your $HOME (current working directory) directory contains the actual file "a/b". Hope this helps, Andrew
pgpgTLoH5lycU.pgp
Description: PGP signature