An exact duplicate has the same bytes as another file. A short PowerShell command groups files by size and compares hashes to find candidates. Review each file’s location, purpose and backups before removing any copy. Leave folders that apps depend on alone; names and dates alone do not establish matching contents.
What counts as a duplicate
Three different things get called duplicates. Content matches still need a review of each file’s purpose and location.
- Same name. Two files called
report.docxin different folders can hold different text. - Same size. Two photos can share a size by coincidence, and a renamed copy keeps its size but loses its name.
- Same content. Every byte matches. Even then, a copy may be a needed backup or referenced at a specific path; check its purpose before removing it.
A hash-based check will not reliably find near-duplicates. A photo saved again at a different quality or a document with one word changed normally has a different hash. Matching SHA256 hashes are strong evidence of matching contents, not a guarantee; review the files and their locations before removal.
Why a hash works
A hash function turns a file's content into a short fingerprint. Microsoft's documentation for Get-FileHash describes matching hashes as a way to compare file contents and says the cmdlet uses SHA256 by default (checked in October 2026). Collisions are possible, though exceptionally unlikely with SHA256. Checking size first saves time because files of different sizes cannot be byte-for-byte matches.
Choose where to look
Decide your scope before you scan. Good places are folders you organise yourself: a photo library, a music folder, a Downloads folder, an archive on an external drive. Poor places are folders where duplicates are expected and on purpose.
C:\Windows,Program FilesandProgramData. Programs keep their own copies of shared files, and removing one can stop a program from starting.- Project and package folders, such as dependency folders in software projects, where tools expect every copy to exist.
- Cloud sync folders, until you know which files are really stored on this PC (see below).
- Backups. A copy that exists for safety looks exactly like a duplicate.
Find exact duplicates with PowerShell
This method only reads files and deletes nothing. Open Windows PowerShell or Terminal, replace the folder path with your own, and run it. It can take a long time on a folder with many large files, and we have not tested this exact line on every Windows 10 and 11 build.
Get-ChildItem "D:\Photos" -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.Length -gt 0 } |
Group-Object Length |
Where-Object { $_.Count -gt 1 } |
ForEach-Object { $_.Group } |
Get-FileHash |
Group-Object Hash |
Where-Object { $_.Count -gt 1 } |
ForEach-Object { $_.Group | Select-Object Hash, Path }
It lists files under the folder and skips empty ones, groups files by size, hashes files in repeated-size groups with SHA256, groups them by hash and prints matching hashes and paths. Matches are candidates for review, not proof that a particular copy is safe to remove.
An empty output means no matching non-empty files were reported; it does not rule out empty files, inaccessible files or errors. Check any errors and review results one group at a time. The cmdlets involved are documented as Get-ChildItem and Get-FileHash.
Careful with OneDrive and other cloud folders
An online-only file does not use the full file's space on your PC, so removing that online-only entry will not reclaim a local copy of its content. Microsoft's OneDrive Files On-Demand page says opening an online-only file downloads it. A script that reads every file to hash it can therefore trigger large downloads, so keep cloud folders out of the scan unless you want that. Removing a file inside a synced folder also removes it from the cloud copy once the sync runs.
Hard links: two paths, one file
On NTFS drives a single file can have more than one name. Microsoft's fsutil hardlink documentation explains that on NTFS volumes each file can have multiple hard links, so one file can appear in many directories, and that programs can open any of the links. Two such entries are not two copies. They are one file with two names. Deleting one name frees no space, and the hash method above will list them as a match because they are the same data.
Windows itself uses hard links heavily in the WinSxS folder, which is another reason to keep system folders out of any duplicate scan.
Decide which copy to keep
For each group of matching files, pick one to keep before you remove anything. Some questions help.
- Which folder is the organised one? Keep the copy in the library you actually use, and remove the stray one in Downloads or on the desktop.
- Does anything point to a copy? Music players, photo apps, shortcuts and documents with linked files can refer to a specific path. Check before removing the one they use.
- Is one a backup on purpose? If so, it is not a duplicate for this purpose.
- Is it still unclear? Keep both and move on. Space saved from one file rarely justifies the risk.
Whichever you pick, make sure at least one verified copy stays. Open it first and check that it is complete.
Remove copies through the Recycle Bin
Select the copy you chose to remove in File Explorer and press Delete. On a normal local drive Windows moves it to the Recycle Bin, where you can restore it until the bin is emptied. Read the confirmation prompt. If it says the file will be permanently deleted, stop. That is how Windows warns you that the Recycle Bin will not hold the file, which can happen on some removable drives and network locations. We have not found a Microsoft page that lists every case, so treat the prompt as the authority. Move the file somewhere else instead, or decide whether you really want it gone.
The bin has a size limit per drive, which you can see by right-clicking the Recycle Bin and choosing Properties. Keep that in mind if you remove large files. Space is not freed until you empty the bin, and emptying is permanent. Wait a few days before you do it, in case you notice that something is missing.
Duplicates that are not worth chasing
Many small matches are not worth your time. Identical icons, config files and library files inside app folders belong to the apps. Removing them saves almost nothing and risks breaking something. A realistic target is large files: videos, disk images, installers, exported archives and photo folders copied twice.
Duplicate file finder in SafeClean
Choose the folders to scan. SafeClean groups files by size, compares them, checks the full contents with a cryptographic hash and checks again just before acting. Folders marked as reference folders are never touched and are preferred as the copy to keep. At least one copy always stays; the others go only to the Recycle Bin, and nothing happens if the Recycle Bin is unavailable. Files that are open, changing or hard-linked to the same data are skipped.
Get SafeClean on Microsoft Store Features and pricing
Frequently asked questions
Can two different files have the same hash?
Different files can share a SHA256 hash, although accidental collisions are exceptionally unlikely. A matching hash is strong evidence, not absolute proof. For irreplaceable files, compare them and keep a separate backup before removing a copy.
Is it safe to delete duplicates found by size and name?
No. Name and size are not proof of identical content. Compare a content hash, review each location and purpose, and keep verified copies and backups.
Will Windows warn me before it deletes something permanently?
Do not rely on a warning appearing in every case. If a prompt says deletion is permanent, the file will not go to the Recycle Bin; stop and review your options.
Why did removing duplicates free no space?
The files may be hard links to the same data, online-only cloud files, or still in the Recycle Bin. Review the bin and restore anything you need before emptying it permanently. Check Size on disk in Properties for local usage.
Does this find similar photos?
No. A resized or re-saved photo has different contents and a different hash. This method finds only exact copies.