bash: ln and relative paths
Hello:
I just tried an 'ln -s' command in bash and got an unexpected result: Code:
root@myhost:/usr/local/pkgs/mypkg# ln -s manual.html /usr/doc/mypkg/ I understand that the fix is to rm the existing link and then: Code:
root@myhost:/usr/doc/mypkg# ln -s /usr/local/pkgs/mypkg/manual.html . |
Yes. "ln" sees this as "create a symlink in /usr/doc/mypkg/". To which file it doesn't know.
You need to think the other way around: Code:
cd /usr/doc/mypkg Code:
cd /usr/doc/mypkg |
Hi Hko:
Quote:
"create a symlink at /usr/doc/mypkg/manual.html that points to /usr/local/pkgs/mypkg/manual.html " ln understood: "create a symlink at /usr/doc/mypkg/manual.html that points to /usr/doc/mypkg/manual.html" The question is, "why?" The form of the ln command (according to the man page) is: Code:
ln src [dest] Code:
ln -s /usr/local/pkgs/mypkg/manual.html /usr/doc/mypkg/manual.html If my current working directory is /usr/local/pkgs/, I should be able to omit that part from either the 'src' or 'dest' part. So (since that is where I was), I should be able to abbreviate the above to: Code:
ln -s manual.html /usr/doc/mypkg/manual.html I am trying to understand why. Is it because: -- I am not understanding how relative paths work under *nix/Linux/slackware -- ln treats relative paths in an unusual but correct way -- the fact that I omitted the filename in the 'dest' part changes something (what?) -- there is a bug in ln or some other reason? Thanks, tortle |
From ln man on solaris:
Quote:
ln has no business guessing what you "intended" to do. Try this: ln -s somefile where "somefile" doesnt exist in the current directory. Then do "vi somefile" ... HTH. |
The dest is a file you create and you can expect exactly the behaviour you're describing, ie omitting the dir path puts the link in your default dir. The source is the contents of the link.
ln -s manual /my/dir/manual1 ln -s /some/dir/manual /my/dir/manual2 cd /tmp ls -l /my/dir/manual1 # same as ls -l manual, ie /tmp/manual ls -l /my/dir/manual2 # same as ls -l /some/dir/manual |
Though I may be misguided, I feel that no real answer was given to tortle's posts in this thread.
The question might be asked again, no ? I wonder whether the problem is perhaps just with the man page where I find : Quote:
Quote:
|
Yes nice to provide the information, but instead of resurrecting an ancient thread, you should have just created your own as an information
only one. The issue you have here is that it will never (well very unlikely due to age) be marked as SOLVED, so your information will still be lost to those users seeking this information as they will disregard any not marked as so. |
I understand your point. However, tortle posts express the problem very clearly and I saw no reason to duplicate them.
Moreover, this thread is easily found on the Web, if you try a search on the ln command, and for that reason is still worth discussing, in my opinion. |
See I am not saying it can't be found, let us face it, you found it, however, the standard on this forum is that once a problem has a solution
it is marked with the word SOLVED. If you look in the search engine you will see that it is also one of the choices you can make, ie to restrict your search to only those marked as SOLVED. Assuming you do this first but do not find a result, when you open your search, most (not all of course) people will ignore anything that is over a certain age as if it has not been SOLVED by now then it is more than likely redundant. |
All times are GMT -5. The time now is 06:32 AM. |