LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   help understanding ln (https://www.linuxquestions.org/questions/linux-general-1/help-understanding-ln-277916/)

dr_zayus69 01-14-2005 07:55 PM

help understanding ln
 
ok i read the man for ln and have a question. To do a symbolic link it has to be:
ln -s TARGET DIRECTORY

Does target mean the file you want to link or the target for the link?

Dark_Helmet 01-14-2005 08:14 PM

TARGET = the real file you want the symbolic link to point to
DIRECTORY = the path (and optionally the name) of the symbolic link itself

As an example:
ln -s /home/someuser/docs/something_important.txt /home/user2

That would create a symbolic link in /home/user2. The real file is /home/someuser/docs/something_important.txt. In this case, the symbolic link's name will also be something_important.txt

One more example:
ln -s /home/someuser/docs/something_important.txt /home/user2/something_stupid.txt
The real file remains the same, the directory the symbolic link is in remains the same, but the symbolic link's name is now something_stupid.txt.

Also, I'm using absolute paths to the real file. That's generally considered bad (because it's not very portable). They will work though. You could use relative paths instead, like:
ln -s ../someuser/docs/something.txt /home/user2/something_stupid.txt

In that command, the target is relative to the location of the link itself. In other words, it's saying, start in /home/user2, create a link named something_stupid.txt, have it point to a file one directory up (/home) & in subdirectory someuser/docs named something_important.txt. Using this method, you can move directories and the symbolic links won't break. If I confused you with that last one, just ignore it. You'll catch on soon enough.

dr_zayus69 01-14-2005 08:22 PM

thanks for the thorough reply. I can of get the last example but it needs to sink in some more.

Dark_Helmet 01-14-2005 08:33 PM

That's to be expected :)

I do want to clarify something though. Using relative links, you have limited ability in moving directories around. As long as the relative path remains unchanged, it will work. For instance, you could move the directories in /home to /home/backup, and it will still work. In other words, going from this:
/home/someuser
/home/user2

to this:
/home/backup/someuser
/home/backup/user2

After re-reading my original post, I was afraid I gave the impression that directories could be moved in any manner. That is not the case. There are limitations, but it's more flexible than using absolute paths.


All times are GMT -5. The time now is 03:52 PM.