Find every copy of a file on a Mac
· 6 min read
Searching the exact filename finds some of the copies. It misses the ones macOS renamed when you duplicated them, the ones a browser numbered on the second download, and anything sitting in a folder Finder does not search by default. Search the stem of the name rather than the whole thing, then prove which results are genuinely the same file by comparing checksums with shasum.
Search the stem, not the filename
Copies rarely keep their name. Duplicating in Finder appends ” copy”, then ” copy 2”. Downloading the same attachment twice produces report-1.pdf or report (1).pdf depending on the browser. Saving from a different application keeps the stem and changes the extension. Emailing a file to yourself and saving it again puts it somewhere else entirely with the original name intact.
So search report, not report.pdf.
- Open a Finder window and press Cmd-F.
- Set the scope under the search field to This Mac.
- Click the plus button, set the row to Name, contains, and type the stem.
- Add a second row of System files set to are included, which brings back results from inside your Library folder.
- Press Cmd-2 for List view, then right-click a column heading and switch on Size, Date Modified and Kind. Click Size to sort.
Sorting by size is the first useful clue. Byte-identical copies have identical sizes, so equal numbers sitting next to each other are your candidates. To see where a result lives, press Cmd-Option-P to show the path bar, or Cmd-I for the full path in Get Info.
Terminal gives the same list in one line, straight from the Spotlight index:
mdfind -name "report"
That prints full paths, one per line, which is easier to scan than a Finder window and easy to feed into the next step. If it returns nothing for a file you can plainly see, the index is behind rather than the file being absent, and Rebuild the Spotlight index on a Mac covers that.
Prove the copies are actually identical
Matching name, size and date is a strong hint and not proof. Two exports of the same document can differ by a timestamp buried in the file and be different by a handful of bytes. A checksum settles it:
shasum -a 256 ~/Documents/report.pdf ~/Desktop/report\ copy.pdf
Pass as many paths as you like. Identical hashes mean identical bytes, with no ambiguity. Note the backslash before the space; dragging a file from Finder into the Terminal window inserts the path correctly escaped.
For two files, cmp is even more direct:
cmp -s fileA fileB && echo identical
And to hash everything the index found in one go:
mdfind -name "report" | while read -r f; do [ -f "$f" ] && shasum -a 256 "$f"; done
Hashes that repeat are the copies. Everything else shares a name and nothing more.
Sweep a whole folder by content
When the question widens from “where are the copies of this file” to “which files in this folder are duplicated”, hash the folder and look for repeats:
find ~/Documents -type f -exec shasum -a 256 {} + > /tmp/hashes.txt
sort /tmp/hashes.txt | uniq -w64 -d
The first line writes a hash and a path for every file. The second sorts them and prints only the lines whose first 64 characters, which is the hash, appear more than once. Take any hash it prints and find its members:
grep "^d2b1a4" /tmp/hashes.txt
This reads every byte of every file, so it is slow on a large folder and honest about it. Narrow it with a size floor, since duplicated small files rarely matter:
find ~/Documents -type f -size +1M -exec shasum -a 256 {} + > /tmp/hashes.txt
The copies that are not copies
Several things look like duplicates in a search result and behave very differently when deleted.
- Aliases and symlinks. Both point at one real file and occupy almost nothing. Get Info calls an alias an alias; in Terminal,
ls -lshows a symlink with an arrow to its target. Deleting the real file leaves the pointer stranded. - Hard links. Two names for one set of bytes. Deleting either name frees no space at all, because the bytes stay until the last name goes.
- Files inside the Photos library or the Mail store. These are packages that Finder shows as one item, and the app owns everything inside. Find the original of a photo inside the Photos library explains how to get an original out properly. Deleting within the package damages the library.
- iCloud Drive placeholders. A file with a cloud icon exists in the account but not on this Mac. It is the same file, not a second one.
- Time Machine and backup copies. Leave them where they are. That is the point of them.
- Document versions. macOS keeps previous versions of documents saved by many apps, invisibly, and they are not files you should hunt for in Finder.
Everywhere finds the other copies in one keystroke
Everywhere catalogs every filename on the Mac and has a shortcut aimed squarely at this: select a result and press Cmd-D to see every other copy of that file. Cmd-Return reveals one in Finder, Space previews it, and Cmd-C copies the full path so you can paste it into a shasum command.
Its useful trick here is reach. It sees inside the Mail store and the Photos library, and it lists files on an external drive that is not currently plugged in, dimmed, naming the drive you need to connect.
The limit to be clear about: it matches names and paths, never file contents. It shows you the candidates quickly; confirming that two of them are byte-identical is still a job for shasum before you delete anything you cannot re-create.
Choosing which copy to keep
- Hash the candidates. If they differ, look at what changed before assuming the newest is the good one.
- Keep the copy in the place you would instinctively look first, not the one with the earliest date.
- Check what refers to it. Design documents, spreadsheets and project files hold links to specific paths, and moving the survivor breaks them just as surely as deleting it.
- Move rather than delete. Put the losers in one folder, use the Mac for a week, then empty it.
- If a large file is the reason you started, Find the largest files on a Mac covers whether removing it will actually free the space.
Questions
Is this the same as running a duplicate finder? No, and the difference matters. This asks “where are the copies of this one file”, which you can verify by eye. A sweep asks “which files anywhere on this disk are identical”, which returns thousands of results, many of them files that apps expect to find in two places. The narrow question is far safer to act on.
Do identical size and date mean identical files? Almost always, and not certainly. Two files can share a size by coincidence, and copying preserves the modification date, so a copy and its original agree on both. A checksum is a second of work and removes the doubt.
Will deleting a copy break an alias that points at it? Yes. An alias can follow a file that has been moved or renamed, which is more than a symlink manages, but nothing survives the file being deleted. If a search result turns out to be an alias, deleting it frees nothing and loses the shortcut.
Why does emptying the Trash not free the space the copies were using? Usually local Time Machine snapshots still holding those blocks, which macOS releases as the disk fills. Occasionally it is hard links: if the copies shared their bytes, removing the extra names freed nothing.