Symbolic Link (newbie)
Hi all,
I am trying to understand what a symbolic link is / does. Using this example... Code:
$ ln -s /usr/local/apache/logs ./logs Can anyone please tell me have I got that right? If so what would I expect to see if I do Code:
$ cat ./logs Thank you... |
You have it correct ... the syntax is:
Code:
ln -s existingfile newname The reason for making a symbolic link is usually for convenience, or if for some reason you have to be able to refer to a file or directory via a different path. This can be convenient if, for example, a program puts its log files in a particular directory, but due to disk space limitations you want them in a different directory on another partition. You might also want to move some files or directories, but leave a link to them at the original location. Note that if you create a symlink to a file and then delete that file, the symlink will not be deleted, but there will be an error (no such file or directory) if you try to read or write its contents. This can be avoided by having a so-called hard link (use ln without the "-s" flag), which will increment the link count of the inode in question. Note that hard links cannot cross filesystem boundaries and that only root may hard link to directories (since it's easy for the unaware to create infinite loops of hard links). |
Quote:
Here is a real case of a symbolic link I have seen for the program 'example' - Code:
$ ln -s /home/www/example/config/apache.conf /etc/apache2/conf.d/example.conf Have I got that right and if so is this effectively the same as copying the file /home/www/example/config/apache.conf to /etc/apache2/conf.d/ and renaming it example.conf? Thanks... |
ln does NOT create a copy, it creates a link (ie a pointer).
See btmiller's comment Quote:
|
Quote:
|
I've had similar questions, if someone could entertain them.
Correct me if I'm wrong, it sounds like Linux sym links are akin to Windows "Shortcuts." In which ways are these two kinds of pointers similar/different? Also, as I understand, hard links are basically pointers to data (rather than the file with sym links). It sounds like, if I edit the main file, the hard link changes with it. If I delete the file, what happens to the hard link? An error? In which ways are hard links different to sym links? Thanks in advance! |
symlinks can cross filesystem (partition) boundaries, hard links cannot.
The data is not removed until all hard links have been removed. Good article here http://linuxcommando.blogspot.com.au...ard-links.html |
Quote:
|
Hate to argue but
Code:
ln x.x x1.x |
Quote:
|
Quote:
|
Original (hard) links are just another name for the same file. When AT&T created unix everything could be viewed from the perspective of the system or the user. The system didn't care about names it used numbers - the (first) inode for the file. ALL file names were links to that inode.
This was easy to see in early system V where directory entries were stored as name/inode pairs. Hence a single hard link to a file causes the link count to show as 2. BSD introduced the (very useful) concept of symbolic links. The file actually stored the name of the file it pointed tto, but not inside the file, inside its inode (I believe, memory getting rusty). Yes, Windows implemented a similar system which they call shortcuts. BTW as should be clear from above, when a file has a hard link ln file1 fle2 and you delete either of them the other stays as is. They are just 2 names for the same thing. The file is only removed when link count drops to 0. |
@rknichols:
I was commenting on Quote:
(and that was a file, not a dir grrrr) . Please ignore previous post :( :( |
All times are GMT -5. The time now is 07:58 AM. |