Hard and Soft linx....Expalnarion needed........
Dear Moderato:Pengy: r,
I'm a new commer to LInux and there arec some issues occured during using program environment.. I have issue on HArd links and soft links of Linux... PLz let me know good discription about it without any confusions.. Thank you.... |
There's an explanation at http://www.granneman.com/techinfo/li...dhardlinks.htm which may help you.
|
Moved: This thread is more suitable in Linux-Newbie and has been moved accordingly to help your thread/question get the exposure it deserves.
The biggest difference (from the user point of view) between soft- and hard links is that you can use soft links between different partitions, but not hard ones. Hard links are like 'having' a file in a specific directory. Files are not connected to directories, hard links represent the connection. Symbolic (soft) link is, in fact, an entry with file name with path, that's interpreted correctly when needed. |
You know how you can put a "Shortcut" on the desktop in Windows? How you can have several "shortcuts" all pointing to the same thing?
A symbolic link (which is the only kind of link you'll need) is like that: it's a reference to another file or directory ... by name. When you use the symlink Linux immediately and invisibly translates that to a reference to the corresponding file or directory. |
the commands for it:
Code:
ln source destination |
Quote:
|
I'm not sure they are, since I think it's true (as noted above) that you can't hardlink to a file on a different partition. With that in mind, you wouldn't be able to have a ../ in the top directory of any partition - but the /home directory will always have a ../ linnking back to /, even if it has its own dedicated partition.
Though I must admit I've never wondered exactly how they're implemented, I've always been happy to use them as-is! |
"." can be looked at as a hardlink of the directory itself.
Likewise, ".." is similar to a hardlink to the parent directory. That's why the link count of a directory (see ls -l) is increased by 1 when you create a subdirectory (the subdir's .. entry is an extra link). The internal mechanism can be simplified to: -Every object has it's own inode, a memory structure that define's it's size, permissions and alike. -Directories contain a list of inode - name pairs of all the objects that are part of the directory. So, they contain something like (inodes are typically referenced by a number): xxx subdir_1 yyy file_1 zzz subdir_2 -Directories also contain 2 special entries, "." and "..". The inode associated with the name "." is the inode of the directory itself (think of it as a "link" to it's own inode). The inode associated with ".." is the inode of the parent directory. -A hard link is nothing more than such a similar directory entry, using the inode of a file (or dir (?)) that already exists on the disk. That's why you can't have hard links to other partitions. Each partition has it's own set of inodes. So with hard links you're having multiple directory entries pointing ("linking") to the same object on disk, just like with the ".." entry. -A soft link is different. You can think of it, as mentioned above, more as a small file that contains the full path to another file/directory anywhere on your filesystem. For the soft link to work, the file/dir that's pointed to must exist and the path leading to it must be searchable. Partition mount points is a different story. It suffices to say that whenever you cross a mount point in a path, ie by doing "cd .." in the partition's top directory like in Dtsazza's example, the mount configuration is used to get you to the right location instead of the directory's entries. The ".." and "." entries of such a mount point directory should point to the directory itself (I think). Simply consider the possibility of mounting the /home partition as the root partition (under "/" instead of "/home"), in which case the "." and ".." entries of / still need to point to / itself for consistency. |
All times are GMT -5. The time now is 10:43 PM. |