32

I've created some hard links on my Windows 7 file system using mklink. It was some time ago and I can't remember for sure where, or which files. When I use Explorer, all files look the same. When I use the command line and type "dir", they all look the same.

How do I find hard links? Or how do I determine whether a specific file IS a hard link?

33

All files are hard links, with link counts of at least 1.

This is why the files look the same. They are the same. What you seem to be looking for are files where there are more than one link to the file. There's very little that distinguishes a file with a link count greater than one from a file with a link count of one … except the link count (and some odd behaviour with respect to attributes and date stamps).

And that is dead easy to check with the find command that is in Microsoft's SFUA utility toolkit, that runs in the Subsystem for Unix-based Applications:

find . -links +1

  • 9
    just as a note, cygwin /bin/find also works. Thanks! – arcyqwerty Sep 18 '12 at 2:25
  • 6
    Just to be clear the "Microsoft find" being referenced in the solution here is not the default installed Windows 7. You have to download and install a new Microsoft find. Then you can use that find utility. Or install Cygwin's find command like @arcyqwerty (which will probably have better support long term). – Trevor Boyd Smith Aug 13 '13 at 14:40
  • 1
    Can also use the built-in fsutil hardlink list filename. (see Sergey's answer) – Svish Jul 30 '17 at 16:53
25

On Windows 7, use command:

fsutil hardlink list MyFileName.txt

It lists all hardlinks to file with name MyFileName.txt.

  • Note that you need to be admin to run fsutil. – Alastair Maw Aug 18 '16 at 17:54
  • 1
    @AlastairMaw On at least Windows 10 you don't need to be an admin to run that particular command. Or does it work to be admin without UAC? (that is, just the group without actual elevation) – Paul Stelian Mar 12 '18 at 22:20
9

Unfortunately, there is no way for the OS to find all your hardlinks without looking at each file.

For Explorer, you can download the very handy Link Shell Extension, which overlays files with hardlinks with a red shortcut-like arrow.

It also makes it rather effortless to create hardlinks, symlinks and junctions through Explorer's context menu.

Bonus chatter:

Technically, all files are hardlinks. Thus, you are really looking for files with more than one hardlink.

  • 1
    Actually, it is. See Sergey's answer. – Svish Jul 30 '17 at 16:51
  • 1
    Sergey's answer works for the second part of the question, but not the first. – surfasb Jul 30 '17 at 21:44
3

use finddupe:

finddupe -listlink c:\photos
  • -listlink Puts finddupe in hardlink finding mode. In this mode, finddupe will list which groups of files are hardlinked together. All hardlinked instances found of a file are shown together. However, finddupe can only find instances of the hardlinked file that are within the search path. – Shayan Jan 3 at 13:51
3

 A simple way for one-off checks: Are file attributes changing together?

If you want to test whether the files A and B are hard links to the same content and you do not want to install or run anything, open the Properties window of file A and toggle for example its Read-only attribute. Now open Properties window of file B to see whether change of the attribute (of file A) took place also here. If yes, then the answer is positive.

Why this works? Because related hard links share the same set of file attributes and time stamps.

This having said, the same test can be made with time stamps of files, but they cannot be changed as easily as Read-only flag in order to perform the check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.