LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   hard links why to use (https://www.linuxquestions.org/questions/linux-newbie-8/hard-links-why-to-use-870504/)

drManhattan 03-23-2011 11:00 AM

hard links why to use
 
Hi

I wonder what is the purpose of using hard links instead of being a shortcut to some file ?

thx for help.

savona 03-23-2011 11:14 AM

A hard link is second filename referencing the same inode (file).

A symbolic link is a shortcut or redirect from one inode to the original.

For this reason hard links MUST be in the same filesystem, soft/sym links can be in different filesystems.


Read more details below, it is a lot to type.

http://www.linuxclues.com/articles/17.htm

http://linuxgazette.net/105/pitcher.html

drManhattan 03-23-2011 11:38 AM

I understand the differences but what I don't understand is when each link is used ?
In which circumstances sys admins use symbolic links and in which hard links ?

thx for help.

savona 03-23-2011 11:44 AM

Quote:

Originally Posted by drManhattan (Post 4300583)
I understand the differences but what I don't understand is when each link is used ?
In which circumstances sys admins use symbolic links and in which hard links ?

thx for help.

Well I personally almost always use sym links. But...

1) Hardlinks are faster (small bit)
2) One hardlink can be deleted but the data still exists. If you delete the data from a sym link you have garbage in the link.


I dont know of any other reasons, like I said I almost always use sym links. But I could see why some people say ALWAYS use hard links if your in the same filesystem. I guess its another one of my bad habits.

szboardstretcher 03-23-2011 12:04 PM

Quote:

Originally Posted by drManhattan (Post 4300583)
I understand the differences but what I don't understand is when each link is used ?
In which circumstances sys admins use symbolic links and in which hard links ?

thx for help.

Hardlinks are faster(1 cpu cycle faster :) )

Hardlinks are,.. sort of inheriting. As in:

If you have a file and you hardlink to it, then delete the file, the hardlink will now be the file.

Symlinks are the opposite of that. If you delete the original file that the symlink points to, you have a meaningless symlink.

As far as when to use hardlinks? If you are using links accross disks/filesystems, then you have to use a Symlink. There are certain situations where you can use hardlinks as a backup: like this http://slaptijack.com/system-adminis...th-hard-links/

Hope this helps.

catkin 03-23-2011 01:02 PM

Two uses of hard links:
  • Hard links allow a single executable to have more than one name; when it is called it can check the name it was called by and behave differently. This is useful when a lot of the code is common. Can be used for binaries and scripts.
  • Hard links allow a single file to be accessed by several paths. This is useful to reduce data volume (not often but it can be). I'm currently working on an automated collation of files collected from multiple computers. There are duplicate files. It is not possible for the program to know which directory paths are the most informative so the program keeps them all and hard links allow that to be done with a single copy of each duplicate file.


All times are GMT -5. The time now is 07:57 AM.