LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-14-2005, 07:55 PM   #1
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Rep: Reputation: 35
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?
 
Old 01-14-2005, 08:14 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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.

Last edited by Dark_Helmet; 01-14-2005 at 08:15 PM.
 
Old 01-14-2005, 08:22 PM   #3
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Original Poster
Rep: Reputation: 35
thanks for the thorough reply. I can of get the last example but it needs to sink in some more.
 
Old 01-14-2005, 08:33 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A better understanding! nny0000 Slackware 1 04-14-2004 12:01 PM
Understanding X?? ++ bdp Linux - General 2 02-25-2004 05:47 PM
Understanding X?? nny0000 Linux - General 2 02-25-2004 02:07 AM
understanding dmesg shanenin Linux - Software 2 12-13-2003 03:00 PM
Understanding df -k itsjustme Linux - General 6 10-28-2003 12:08 PM


All times are GMT -5. The time now is 08:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration