NTFS data files are stored with all their attributes as an "inode" with an ID, and filenames point to the inode. All files have one+ hardlink. some tools can create extra names (hardlinks) which point to the same inode, which has a counter of the number of names pointing to it. If the number goes to zero, the OS deletes the file, the inode.
Special tools, like LN can create additional filenames which point to existing inodes, using a filename that points to them. Note that all the file attributes, including dates and times are stored with the inode, not the filename.
(Extra) hardlinks are useful when you want different names to point to the same data, read or write. They save space and overhead. However, they clobber programs which assume different names point to different data. e.g, if you replace references to duplicate files by hardlinks to a single file, then you have removed any backup you have! The windows OS is one program which assumes different names point to different sets of bits.
Hardlinks have to be on the same physical and logical volume.
They are useful for:
reducing path lengths since Windows just supports 256 characters or so.
reducing storage space of duplicate data files - eg, you could have multiple backups of a partition with multiple complete directory trees, but with hardlinks for files which have not changed since the previous backup.
Junction points are messier and use Reparse Points (which I do not understand). They can point to different physical or logical volumes but they have to be on the same computer. They apparently can be used like symlinks for directories, allowing a second name for the same destination, but limited to a single computer, rather than just a single volume.
Useful for reducing path lengths, or simplifying working with several programs with hardcoded directory names.
Same caveats, too! Many programs assume different names = different files.
And then there are symbolic links (which can go across networks), shortcuts and PIFs and .....
Also some information from Microsoft itself:
Basically, they're saying to use hard links only for files within the same volume (disk drive letter) and junction points only for directories on the same computer (they can span across different local volumes).
cmd
includes the mklink
command which can create hardlinks:
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D
Creates a directory symbolic link. Default is a file symbolic link.
/H
Creates a hard link instead of a symbolic link.
/J
Creates a Directory Junction.
Link
specifies the new symbolic link name.
Target
specifies the path (relative or absolute) that the new link refers to.
Furthermore, the excellent Far Manager has support for creating them (Alt+F6).
There are also a number of shell extensions that allow for doing so.
Best Answer
Try using Sysinternals Disk Usage (otherwise know as
du
), specifically using the-u
and-v
flags will only count unique occurrences, and will show the usage of each folder as it goes along.As far as I know the file system doesn't show the difference between the original file and a hard link (that is really the point of a hard link) so you can't discount them on a folder-by-folder basis, but need to do this comparatively.
To test I created a random folder with 6 files in to. Cloned the whole thing. Then created several hard and soft links inside the first folder to reference other files in the first folder, and also some in the second.
Running
du -u -v testFld
results in (note the values next to the folders are in KiB):Running
du -u -v testFld\a
results in:Running
du -u -v testFld\b
results in:Notice the mismatch?
The symlinks in A that refer to files in B are only counted against A during the "full" run, and B only returns 54 (even though the files were originally in B and hard-linked from A). When you measure B seperately (or, if you don't use the
-u
unique flag) it will count its "full" measure of 74.