50

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?

Breakthrough
  • 34,847
MM.
  • 683

9 Answers9

70

On Windows 7 (also works on Windows 10), use command:

fsutil hardlink list MyFileName.txt

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

buhtz
  • 349
Sergey
  • 709
48

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 Windows Subsystem for Linux: find . -links +1.

p.s. Windows Subsystem for Linux was previously called "Subsystem for UNIX-based Applications" in 2008 for Windows-Server-2008 (for more info read here https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc772343(v=ws.11)?redirectedfrom=MSDN ).

JdeBP
  • 27,556
  • 1
  • 77
  • 106
16

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
  • 22,896
4

use finddupe:

finddupe -listlink c:\photos
eadmaster
  • 1,356
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
  • 14,845
2

I wrote a program that searches an directory, optionally recursive, for any kind of link. It can output to stdout or as a tab separated table (tsv) for reading in Excel/Libreoffice.

Source code can be found on my Github repo JavaScriptDude/find_links

find_links - Finds any kind of link in windows 
Usage: find_links -p <path> [-r] [-x] [-t] [-f <filter>]
-path | -p: Path to search (required)
-recurse | -r: recursive search
-exec | -x: Open tsv using explorer
-tsv | -t: Output in tsv format (tab separated)
-filter | -f: Filter the target using optional wildcards Eg: *foo*
2

There is no need to download anything.
You can CD to desired folder and do a recursive search:

echo off & for /F "delims=" %A in ('dir /s /b') do echo. & fsutil hardlink list "%A"

A single isolated line means it's a normal file
Two adjacent lines means it's a HardLink.

mjoao
  • 151
  • 2
1

This works in Windows 10 as well as 11, no downloads required. Basic idea, use command prompt (elevated recommended) Navigate to the folder you want to check. Execute this command to list ALL FILES in the folder and subfolder, so don't do a huge drive all at once. As noted below, hardlinked files will appear twice.

echo off & for /F "delims=" %A in ('dir /s /b') do echo. & fsutil hardlink list "%A" > "%UserProfile%\Desktop\HardLinks.txt"

A single isolated line means the it's a normal file. You can ignore this. Two lines together means it's a hard link. The top path will be for the hard link, and the bottom path will be for it's target source.

The first part of the article discusses listing Symbolic Links and Junction Points.

Reference: https://www.elevenforum.com/t/find-all-symbolic-links-and-junction-points-in-windows.4225/

I'm busy with taxes at the moment, but I feel like it would be fairly straightforward to write a simple script to remove the duplicate listings and only output the hard links. Maybe I'll ask my son.

0

In Windows 11 I just open the folder, that holds this hard link and run the command dir. That is all. Look at result. In mu case it is the PostgreSQL pg_tblspc folder. PostgreSQL keeps hard links here to the tablespaces:

C:\PostgreSQL\9.5\data\pg_tblspc>dir  Volume in drive C has no label. 
 Volume Serial Number is 10B4-2DC6

Directory of C:\PostgreSQL\9.5\data\pg_tblspc

23/04/2019 07:34 AM <DIR> . 11/02/2025 06:54 PM <DIR> .. 23/04/2019 07:09 AM <JUNCTION> 134931 [??\C:\PostgreSQL\9.5\shadb] 23/04/2019 07:34 AM <JUNCTION> 134990 [??\C:\PostgreSQL\9.5\nlp] 23/04/2019 05:28 AM <JUNCTION> 16395 [??\C:\PostgreSQL\9.5\data\balancedb] 23/04/2019 06:37 AM <JUNCTION> 16615 [??\C:\PostgreSQL\9.5\data\idrakdb]