iwato Posted June 5, 2010 Share Posted June 5, 2010 QUESTION: The link( ) function creates something called a hard link. The discussion surrounding the link( ) function bespeaks soft links. What is the difference, and to what end would one use either?Could someone please provide a code example of how a hard link is used?Roddy Link to comment Share on other sites More sharing options...
boen_robot Posted June 5, 2010 Share Posted June 5, 2010 A soft (symbolic) link is like a shortcut on Windows - you have a location on your hard drive that points to a certain other location. Upon following it, you arrive to the "real" location. In other words, you have "1 path = 1 file/folder".A hard link is more like a file/folder-to-HDD mapping. You have one or more paths. On early Windows versions, you have a "1 file/folder = 1 HDD location". On UNIX, and from Windows Vista on, you instead have a "N files/folders = 1 HDD location".So, by creating a hard link, you're creating another file/folder that points to the same HDD location as pointed by the other file/folder you specify during the creation.Now... where's the benefit you may ask? A hard link is treated the same as the original file/folder. It actually becomes another original file/folder. If you first create a hard link from file A to a location B, and then delete A, you can still access the content from B. If you instead had a symbolic link B, the original being A, then deleting A would mean that by following B, you'll arrive to A, which is no longer present. Link to comment Share on other sites More sharing options...
iwato Posted June 7, 2010 Author Share Posted June 7, 2010 So, by creating a hard link, you're creating another file/folder that points to the same HDD location as pointed by the other file/folder you specify during the creation.I got it.I have created my first hard link. Hooray!Roddy Link to comment Share on other sites More sharing options...
iwato Posted June 7, 2010 Author Share Posted June 7, 2010 So, by creating a hard link, you're creating another file/folder that points to the same HDD location as pointed by the other file/folder you specify during the creation.I am writing a second reply for two reasons:1) I want to apologize to boen_robot for not providing a more thorough reply to his very helpful answer. Unfortunately, however, I have run into serious trouble communicating with the W3Schools forum web application and am trying to discover why.2) This is a second test. Once I have overcome the problem, I will provide a more thorough response. In the meantime I am very pleased to announce that I now have a good understanding of how hard links work.Roddy Link to comment Share on other sites More sharing options...
iwato Posted June 7, 2010 Author Share Posted June 7, 2010 So, by creating a hard link, you're creating another file/folder that points to the same HDD location as pointed by the other file/folder you specify during the creation.The problem addressed in my last reply is both temporary and erratic, and my recent success has encouraged me to provide a more appropriate response now.What I discovered after creating my first hard link is that any change made to the file DESIGNATED by the $from_path parameter of the link( ) function is automatically reflected in the file CREATED by the $to_path parameter of the same function call. It is as if the file designated by the $from_path parameter were copied and placed at the location designated by the $to_path parameter, and both files made to behave as mirror images of one another.In effect, the link( ) function appears to be powerful little tool.My success with hard links caused me to return to soft (symbolic) links, and I discovered that unless the file created by the symlink() is placed in the same folder in which the file designated by the $target parameter is located, the file thus created fails to find the targeted file when clicked upon. This appears to be an important limitation of the soft link.Once again, boen_robot and everyone else for your terrific support.Roddy Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.