How to find duplicate files on your Mac
Two files are duplicates when every byte is the same. Names, sizes and dates only hint at that. The reliable method is to group files by size, then compare a hash of their contents: shasum -a 256 in Terminal does this. Files with the same SHA-256 hash are identical for every practical purpose, and you can then choose which copy to keep.
Why name and size matching is unreliable
Many guides tell you to sort a folder by name or size and look for twins. It fails in both directions.
- Same name, different content. Two cameras both write
IMG_0001.JPG. Every "Untitled.docx" and "report.pdf" is a different file. Deleting one because the name matched loses the only copy. - Different name, same content.
invoice.pdfandinvoice (1).pdffrom a second download. A name match never finds these, and they are the most common duplicates there are. - Same size, different content. Disk images, preallocated files, encrypted containers and many database files are a fixed size whatever is in them. A one-character edit in a PDF form can leave the size unchanged.
- Same everything but the date. Copying a file changes its created date, so date matching rejects true copies.
Size is still useful as a cheap first filter. Two files of different size cannot be identical, so you only hash files that share a size.
What hashing does
A hash function reads a file and produces a fixed-length fingerprint. Change one bit and the fingerprint changes completely. SHA-256 produces 64 hexadecimal characters. Finding two different files with the same SHA-256 is not a realistic accident, so a matching hash means matching content. Older MD5 (md5 -q file) is faster but can be forged on purpose. For an accidental duplicate hunt it is fine, but SHA-256 costs little extra.
$ shasum -a 256 /etc/hosts
c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da /etc/hosts
The cost is reading every candidate file in full, so hashing a whole disk is slow. That is why you narrow by size first.
Method 1: Terminal, by content
This hashes every file over 1 MB in Downloads and Documents, sorts by hash, and prints only hashes that appear more than once:
find ~/Downloads ~/Documents -type f -size +1M -exec shasum -a 256 {} + 2>/dev/null \
| sort \
| awk '{ if ($1 == prev) { if (!shown) print line; print; shown = 1 } else shown = 0; prev = $1; line = $0 }'
Output is grouped, with each group sharing a hash:
aaa... /Users/you/Downloads/invoice.pdf
aaa... /Users/you/Downloads/invoice (1).pdf
This version hashes everything, so it is slow on large folders. Skip small files (the -size +1M filter) because duplicate small files rarely matter. To confirm one pair before you delete, compare byte for byte:
cmp -s "file A" "file B" && echo identical
Reading these commands removes nothing. Acting on the list is manual: move the extra copies to the Bin in Finder. This is recoverable until you empty the Bin.
Method 2: Finder
Finder has no duplicate finder. The nearest thing is a Smart Folder (File > New Smart Folder) filtered by Kind and sorted by Name, which is the name matching the section above warns about. In Photos, Albums > Utilities > Duplicates exists on macOS 13 and later and merges duplicate photos inside the library. Do not open Photos Library.photoslibrary and delete files by hand. That corrupts the library.
What most articles skip: which copy, and what is not really a copy
Hard links. Two paths can point at the same data on disk. Deleting one frees nothing. ls -li shows the inode number in the first column, and the same number means the same file.
APFS clones. Duplicate in Finder (Cmd+D) and copy-paste within the same APFS volume create clones that share blocks until one is edited. Finder reports the full size for both. Removing one of two untouched clones frees little or nothing, so a 5 GB "wasted" figure can be an overstatement. The hash method above cannot see this. Both files hash equal and look like a saving.
Which one to keep. Keep the copy something refers to. Music and Final Cut libraries, project files, aliases and apps that remember a path break if you remove the file they point to. Keep the one in the folder you actually use, and delete the one in Downloads.
Packages and dependency folders. Do not scan them. App bundles, node_modules and .git hold many identical files by design. Removing them breaks the app or the project.
If every copy in a group is removed, nothing remains. Always leave one.
Using Spotless for this
Spotless finds duplicates the same way as the Terminal method, with a few safeguards. It groups files of 1 MB and over in Desktop, Documents, Downloads, Pictures, Movies and Music, plus folders you add. It groups by size, compares a sample of each file (the first and last 64 KB, plus the middle on large files), then runs a full SHA-256 only on files that still match. It counts hard-linked paths as one file, estimates the space you really get back on APFS, and refuses to let you tick every copy in a group. Nothing is ticked after a scan, and removed copies go to the Trash first.
Spotless matches identical files only. It does not judge two similar-looking images, and it does not download iCloud files that are not on disk to compare them. See Duplicates.
Keep going
- Storage by type: see which kind of file fills your Mac: Spotless groups the files in your home folder by type and age, from app data and developer files to videos, with the biggest files in each group.
- How a Spotless clean works: Scan, look, choose, review, Trash.
- Pricing: Every feature for $9, once.