How to find and remove duplicate files on a Mac

Duplicates pile up from downloading the same file twice, copying project folders and importing photos more than once. Removing them is easy. Being sure two files really are identical before you delete one takes more care.

What makes two files duplicates

A file named report (1).pdf next to report.pdf is probably a copy, but not certainly. The only reliable test is comparing contents. Matching names or sizes are hints, not proof.

Duplicate photos

If the duplicates are in your Photos library, use the Photos app rather than Finder. Open Photos and choose Duplicates in the sidebar under Utilities to merge them. Never delete files from inside the Photos Library package in Finder.

In Finder

For a small folder, a List view sorted by Size puts files of equal size next to each other, and Quick Look (Space) lets you compare them. It works for a folder or two, but it doesn’t scale and proves nothing.

In Terminal

To check whether two files are byte-for-byte identical:

shasum -a 256 "file one.pdf" "file two.pdf"

If the two hashes match, the contents are identical. Checking a whole folder this way means hashing every file, which is slow.

With SpareDisk

SpareDisk checks duplicates in stages. It groups files of the same size, compares samples from the start, middle and end, then compares SHA-256 hashes and finally the bytes themselves. Only identical contents are grouped. You choose the copy to keep in each group, and Stage the Rest for Review queues the others. The copy you keep is never moved, and SpareDisk refuses to remove the last copy in a group.

Three things to check before deleting

Where each copy lives

An identical file can belong to different apps: a library bundled with two apps, an asset in two projects, a document one app links to by path. Don’t remove duplicates inside app bundles or Library folders.

APFS clones

When you duplicate a file in Finder on an APFS disk, macOS makes a clone that shares storage with the original until one of them changes. Two clones look like duplicates, but deleting one frees almost nothing.

Hard links

A hard link is one file with two names. Deleting one name frees nothing. SpareDisk counts hard links once and labels them, so they never appear as duplicates.

Questions

Does macOS have a built-in duplicate file finder?
Only for photos: the Photos app has a Duplicates album under Utilities. For other files you can compare hashes in Terminal or use an app that compares contents, such as SpareDisk.
Is it safe to delete duplicate files on Mac?
It is safe once you have confirmed the contents are identical and checked that no app depends on that copy’s location. Move copies to the Trash rather than deleting them permanently, so you can restore one if something breaks.
Why did deleting duplicates free less space than expected?
The copies were probably APFS clones, which share storage until one changes, or hard links, which are one file under two names.