How can I find hard links on Windows?

33

14

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?

MM.

Posted 2011-12-11T01:23:25.450

Reputation: 483

Answers

34

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

JdeBP

Posted 2011-12-11T01:23:25.450

Reputation: 23 855

2

Can also use the built-in fsutil hardlink list filename. (see Sergey's answer)

– Svish – 2017-07-30T16:53:25.793

10just as a note, cygwin /bin/find also works. Thanks! – arcyqwerty – 2012-09-18T02:25:47.140

6Just 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 – 2013-08-13T14:40:48.603

28

On Windows 7, use command:

fsutil hardlink list MyFileName.txt

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

Sergey

Posted 2011-12-11T01:23:25.450

Reputation: 281

Note that you need to be admin to run fsutil. – Alastair Maw – 2016-08-18T17:54:44.673

2@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 – 2018-03-12T22:20:38.970

10

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.

surfasb

Posted 2011-12-11T01:23:25.450

Reputation: 21 453

1

Actually, it is. See Sergey's answer.

– Svish – 2017-07-30T16:51:06.757

1Sergey's answer works for the second part of the question, but not the first. – surfasb – 2017-07-30T21:44:25.873

3

use finddupe:

finddupe -listlink c:\photos

eadmaster

Posted 2011-12-11T01:23:25.450

Reputation: 706

-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 – 2019-01-03T13:51:06.533

2

 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.

miroxlav

Posted 2011-12-11T01:23:25.450

Reputation: 9 376