LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Hard and Soft linx....Expalnarion needed........ (https://www.linuxquestions.org/questions/linux-newbie-8/hard-and-soft-linx-expalnarion-needed-401047/)

chamith20xx 01-08-2006 10:06 PM

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....

gilead 01-08-2006 10:19 PM

There's an explanation at http://www.granneman.com/techinfo/li...dhardlinks.htm which may help you.

Mara 01-09-2006 03:36 PM

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.

sundialsvcs 01-09-2006 06:36 PM

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.

muha 01-10-2006 05:27 AM

the commands for it:
Code:

ln source destination
Create a hard link called destination to the file called source.
The link appears as a copy of the original files, but in reality only one copy of the file is kept,
just two (or more) directory entries point to it. Any changes the file are automatically visible throughout.
When one directory entry is removed, the other(s) stay(s) intact. The limitation of the hard links are:
the files have to be on the same filesystem, hard links to directories or special files are impossible.

ln -s source destination
Create a symbolic (soft) link called "destination" to the file called "source".
The symbolic link just specifies a path where to look for the file. In contradistinction to hard links,
the source and destination don't not have to tbe on the same filesystem. In comparison to hard links,
the drawback of symbolic links are: if the original file is removed, the link is "broken",
symbolic links can also create circular references (like circular references in spreadsheets
or databases, e.g., "a" points to "b" and "b" points back to "a").

from http://www.unixguide.net/linux/linuxshortcuts.shtml

merchtemeagle 01-10-2006 06:42 AM

Quote:

Originally Posted by muha
hard links to directories or special files are impossible.

I always thought the ./ and ../ in a directory are hardlinks to the parent directory?

Dtsazza 01-10-2006 07:53 AM

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!

timmeke 01-10-2006 09:06 AM

"." 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.