Hard links vs. shortcuts

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

Bill Martz
New Member
Posts: 7
Joined: 2004 Jul 01, 14:36

Hard links vs. shortcuts

Post by Bill Martz »

What is the advantage to using hard links as opposed to using shortcuts? With hard links how do you know when you are deleting the last link, and therefore, the file itself?
wasker
Gold Member
Gold Member
Posts: 799
Joined: 2005 Oct 21, 16:33
Location: WA, USA
Contact:

Post by wasker »

They're different beasts.

Shortcut is a Windows shell feature which simplifies file access (merely launching the executable/document) for user. Hardlink is a file system feature. Hardlinked file is the same file for any program which tries to access it from both the original and linked locations.
I'm using Xplorer2 - the only file manager that does not suck. Actually, it rocks!
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

With hard links how do you know when you are deleting the last link, and therefore, the file itself?
x2 has a "stock" column called "links'. Activate it (using ALT+K command) (details view only). Now you will see how many links the item has. By default, each file starts its life with 1 link. When you add a hard link to it anywhere (on the same NTFS disk), the count goes up.

When you see only 1 link in the column, that's the last copy.

I just noticed that the User Manual does not cover any of this (including the warning that deleting the last hard link will delete the item itself). I will add it.
Mr.Pleasant
Silver Member
Silver Member
Posts: 281
Joined: 2006 Dec 29, 12:56
Location: Utrecht, NL

Post by Mr.Pleasant »

When you see only 1 link in the column, that's the last copy.
There's one thing you'd have to be aware of, though. When you see there's more than 1 link in the column, it might be the case that the other copy/copies are in the trash-can already. The copies in the thrash-can do add to the number in the link column.

Knowing the technical difference between shortcut and hard-link doesn't really answer what the advantage is of using the one compared to using the other. I also wondered how I could make better use of these features, but I couldn't think of situations in which you'd need hardlinks instead of shortcuts. Makes me curious if anyone is actively using hardlinks for one particular reason.  :confused:
Robert2
Gold Member
Gold Member
Posts: 671
Joined: 2004 Jun 17, 15:39

Post by Robert2 »

Hi,
Here are a few pointers gleaned from the Web:

http://www.flexhex.com/docs/articles/hard-links.phtml
A link is basically an alternate name for a file or a directory. In many cases creating a link is preferable to making several copies of the file. Links save disk space and more important, if the file should be changed afterwards, you will not have to edit a bunch of copies - all the links point to the same file.

http://www.askdavetaylor.com/how_do_uni ... _work.html
The main point of hardlinks is to allow a single data entity to be shared by multiple entries in the file system. If I saved this posting as "001.html" on my server, then created a hard link to the same file from "002.html", then I could subsequently delete "001.html" and "002.html" would be unaffected, with the same contents within. It's only when all links to a data entity are removed that the data gets hooked into the free list and is essentially recycled for later reuse.
In terms of your specific question, the system will view the two files as having separate content.

http://shell-shocked.org/article.php?id=284
These differences result in different behavior for hard and soft links. Hard links are unbreakable, for example; because the information you see in your file browser, such as the file name, is stored in the filesystem table, and not at the disk address referenced in the filesystem table, this information can be changed at will without risk of affecting that link or any other link. It has to be this way, or filesystems would never work to begin with! Meanwhile, symbolic links, which rely on paths, break when you move or rename the target. As files and not filesystem record entries they are more independent of the target, which is good for operations like delete.
...
Windows "junctions" or directory reparse points, while some (such as the Winbolic site) may call them "hard links" or even hard-link-like, are not hard links, because: you can create a Windows symlink to a non-existent folder; you can break a symlink by renaming a symlink's target folder; and you can "fix" a symlink by creating a folder having the name targeted by a symlink. In other words, these links are clearly path-based, and not dependent on disk address or anything on that level. This actually is evident in that the symlinks work across partition boundaries, unlike hard links.
A Windows shortcut is like a symbolic link, and sometimes people speaking of symlinks call it a symlink, but it isn't strictly a symlink. A crucial characteristic of a symbolic link is that the OS will manage any calls to it as if they were calls to the link's target. Windows doesn't do that for shortcuts, so they're not real symlinks.

http://en.wikipedia.org/wiki/Hard_link
Additional links can also be created to the physical data. The user need only specify the name of an existing link; the operating system will resolve the location of the actual data section.
If one of the links is removed (ie, with the UNIX 'rm' command), then the data is still accessible under any other links that remain. If all of the links are removed and no process has the file open, then the space occupied by the data will be considered free, allowing it to be reused in the future for other files. This semantic allows for deleting open files without affecting the process that uses them - an action which is impossible on filesystems with a 1-to-1 relationship between directory entries and data.

So the main benefit of hard links vs shortcuts for Windows users seems to be that files referred to by hard links can be moved without invalidating the hard link. On the other hand, moving a file referred to by a shortcut invalidates the shortcut.
Hope this helps.
Cheers,
Robert
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

On the other hand, moving a file referred to by a shortcut invalidates the shortcut.
Not so: The User Manual lists the various circumstances under which you can rename and move the shortcuts.
Robert2
Gold Member
Gold Member
Posts: 671
Joined: 2004 Jun 17, 15:39

Post by Robert2 »

narayan wrote:
On the other hand, moving a file referred to by a shortcut invalidates the shortcut.
Not so: The User Manual lists the various circumstances under which you can rename and move the shortcuts.
Hi Narayan,
I think there is a misunderstanding here.
I did not mean to say that the Windows standard shortcuts cannot be moved.
I meant to say that the corresponding files cannot be moved.
In other words, if you move files, the shortcuts that are targeting them are no longer valid.
Cheers,
Robert
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

Even the target can be moved/renamed!
User avatar
fgagnon
Site Admin
Site Admin
Posts: 3737
Joined: 2003 Sep 08, 19:56
Location: Springfield

Post by fgagnon »

of course you can move or rename the target file(s), but any shortcuts to them become broken if they are on different partitions. [edit/add (something new I just learned)] However, when the shortcut and target are on the same partition (and remain on the same partition) the shortcut will seamlessly track changes in the target (same as hardlink functionality).
Of course hardlinks always only apply to items on the same NTFS partition; whereas shortcuts can cross partitions, and are not limited to NTFS; but won't "track" target changes unless they are.
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

The shortcuts need not be on the same partition, hard disk or even on the same PC. The shortcut continues to point at the target, provided that the two are connected when these changes are made.

For example, if the shortcut is to a file residing on a NN PC, then the PCs must be connected when the target/shortcut are moved/renamed.

Similarly, if the target file is on removable media (e.g. a USB drive), then the medium must be connected to the PC when the target and/or shortcut is moved and/or renamed.
User avatar
fgagnon
Site Admin
Site Admin
Posts: 3737
Joined: 2003 Sep 08, 19:56
Location: Springfield

Post by fgagnon »

This is very curious in my tests, same-partition operation is seamless -- cross partition (another local HD, not even going NN route) the shortcut loses its connection as shown in x2 on the s/c r-click properties tab.
But ... after "opening" the s/c with an app (I am testing with photo viewer ACD See and s/c to a jpg file) then the s/c finds the renamed or moved target, and all becomes well.  
Enough mystery for tonight -- past my bed time, even though you are already well into your Monday morning, narayan.
I'm turning in now .... :spin:
-fg-
BRX
Silver Member
Silver Member
Posts: 304
Joined: 2002 Feb 08, 12:12

Post by BRX »

Robert2 wrote: So the main benefit of hard links vs shortcuts for Windows users seems to be that files referred to by hard links can be moved without invalidating the hard link. On the other hand, moving a file referred to by a shortcut invalidates the shortcut.
Hope this helps.
Cheers,
Robert
I'm using hardlinks all the time. That's why the convenient HL-feature is in my personal Top 5 of x2 functions.

While the above certainly is true there are two additional benefits which are invaluable.

If you "copy" files or directories by hardlinking there's no increase in space and of course it's quick because there are only new hardlink references to create. Not so for shortcuts. Might not sound spectacular, but if there's not much size on the harddisk left and you need some serious file organizing, preferably with the original dir/files as "backup" that's the way to go.
narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan »

Each shortcut occupies 100-400 bytes. Considering how many shortcuts we actually use, the overall size would be negligible.
User avatar
pschroeter
Silver Member
Silver Member
Posts: 283
Joined: 2007 Jan 27, 00:46

I would love to see a table comparing shortcuts, hardlinks

Post by pschroeter »

I would love to see a table comparing the features, advantages and disadvantages of shortcuts vs hardlinks vs symbolic links vs junction points.

Frankly, hardlinks and junction points scare me. I can't seem to wrap my mind around them and feel comfortable with them. They sound useful, but I would want to use them for folders and would be afraid I was deleting an actual folder rather than just a link.  I don't want to turn on another column just to use a few.
Last edited by pschroeter on 2008 Feb 25, 21:46, edited 1 time in total.
Mr.Pleasant
Silver Member
Silver Member
Posts: 281
Joined: 2006 Dec 29, 12:56
Location: Utrecht, NL

Post by Mr.Pleasant »

I could imagine a situation where hardlinks can be very useful. Say, you're building several independent pieces of documentation in HTML files with linked images, and you want to reuse a certain image in each of the sets of documentation.
Since the documentation is independent, and therefore not in one folderstructure (you're doing things in an orderly manner!), you can't put this image in one folder, and then link to this place in all HTML files in which the image shoud occur. This would be inconvenient, because you couldn't move the separate folderstructures of each set of documentation to another place without losing the link to the image.
In this case you could use hardlinks to put the same image in several places (it wouldn't work with shortcut links) to (1) save storage room, and (2) make it possible to do some editing on the image without having to update all other occurances of the image.
That's why I like the feature: it's good to know it, and use it to your benefit. But I have never used it in practice, although creating this kind of environments full of links is part of my job  :roll:
Post Reply