back
456 comments
I made a command line utility called `dedup` a while back to do the same thing. It has a dry-run mode, will “intelligently” choose the best clone source, understands hard links and other clones, preserves metadata, deals with HFS compressed files properly. It hasn’t destroyed any of my own data, but like any file system tool, use at your own risk.

0 - https://github.com/ttkb-oss/dedup

Replying to myself now that I've had a chance to try the scan, but not the deduplication. I work with disc images, program binaries, intermediate representations in a workspace that's 7.6G.

A few notes:

* By default it doesn't scan everything. It ignores all files but those in an allow list. The way the allow list is structured, it seems like Hyperspace needs to understand the content of a file. As an end user, I have no idea what the difference between a Text file and a Source Code file would be or how Hyperspace would know. Hyperscan only found 360MB to dedup. Allowing all files increased that to 842MB.

* It doesn't scan files smaller than 100 KB by default. Disabling the size limit along with allowing all files increased that to 1.1GB

* With all files and no size limit it scanned 67,309 of 68,874 files. `dedup` scans 67,426.

* It says 29,522 files are eligible. Eligible means they can be deduped. `dedup` only fines 29,447. There are 76 already deduped files, which is an off-by-one, so I'm not sure what the difference is.

* Scanning files in Hyperspace took around 50s vs `dedup` at 14s

* It seems to scan the file system, then do a duplication calculation, then do the deduplication. I'm not sure why the first shouldn't be done together. I chose to queue any filesystem metadata as it was scanned and in parallel start calculating duplicates. The vast majority of the time files can be mismatched by size, which is available from `fts_read` "for free" while traversing the directory.

* Hyperspace found 1.1GB to save, `dedup` finds 1.04GB and 882MB already saved (from previous deduping)

* I'm not going to buy Hyperspace at this time, so I don't know how long it takes to dedup or if it preserves metadata or deals with strange files. `dedup` took 31s to scan and deduplicate.

* After deduping with `dedup`, Hyperscan thinks there are still 2 files that can be deduped.

* Hyperspace seems to understand it can't dedup files with multiple hard links, empty files, and some of the other things `dedup` also checks for.

* I can't test ACLs or any other attribute preservation like that without paying. `strings` suggests those are handled. HFS Compression is a tricky edge case, but I haven't tested how Hyperspace's scan deals with those.

Thank you for creating and sharing this utility.

I ran it over my Postgres development directories that have almost identical files. It saved me about 1.7GB.

The project doesn't have any license associated with it. If you don't mind, can you please license this project with a license of your choice.

As a gesture of thanks, I have attempted to improve the installation step slightly and have created this pull request: https://github.com/ttkb-oss/dedup/pull/6

Just tried it, and it works well! I didn't realize the potential of this technique until I saw just how many dupes there were of certain types of files, especially in node_modules. It wasn't uncommon to see it replace 50 copies of some js file with one, and that was just in a specific subdirectory.

I see it is "pre-release" and sort of low GH stars (== usage?), so I'm curious about the stability since this type of tool is relatively scary if buggy.

Wow, that's some excellent documentation.

I was also really impressed that `make` ran basically instantly.

See the comments on https://news.ycombinator.com/item?id=38113396 for a list of alternatives. I used https://github.com/sahib/rmlint in the past and can't complain.
> There is no way for Hyperspace to cooperate with all other applications and macOS itself to coordinate a “safe” time for those files to be replaced, nor is there a way for Hyperspace for forcibly take exclusive control of those files.

This got me wondering why the filesystem itself doesn't run a similar kind of deduplication process in the background. Presumably, it is at a level of abstraction where it could safely manage these concerns. What could be the downsides of having this happen automatically within APFS?

On ZFS it consumes a lot of RAM. In part I think this is because ZFS does it on the block level, and has to keep track of a lot of blocks to compare against when a new one is written out. It might be easier on resources if implemented on the file level. Not sure if the implementation would be simpler or more complex.

It might also be a little unintuitive that modifying one byte of a large file would result in a lot disk activity, as the file system would need to duplicate the file again.

This is commonly done with compression on block storage devices. That fails, of course, if the file system is encrypting the blocks it sends down to the device.

Doing deduplication at this level is nice because you can dedupe across file systems. If you have, say, a thousand systems that all have the same OS files you can save vats of storage. Many times, the only differences will be system specific configurations like host keys and hostnames. No single filesystem could recognize this commonality.

This fails when the deduplication causes you to have fewer replicas of files with intense usage. To take the previous example, if you boot all thousand machines at the same time, you will have a prodigious I/O load on the kernel images.

This is the standard API for deduplication on Linux (used for btrfs and XFS); you ask the OS nicely to deduplicate a given set of ranges, and it responds by locking the ranges, verifying that they are indeed identical and only then deduplicates for you (you get a field back saying how many bytes were deduplicated from each range). So there's no way a userspace program can mess up your files.
> This got me wondering why the filesystem itself doesn't run a similar kind of deduplication process in the background.

I think that ZFS actually does this. https://www.truenas.com/docs/references/zfsdeduplication/

I love the model of it being free to scan and see if you'd get any benefit, then paying for the actual results. I, too, am a packrat, ran it, and got 7GB to reclaim. Not quite worth the squeeze for me, but I appreciate it existing!
What algorithm does the application use to figure out if two files are identical? There's a lot of interesting algorithms out there. Hashes, bit by bit comparison etc. But these techniques have their own disadvantages. What is the best way to do this for a large amount of files?
Just want to mention: Apple ships a modified version of the copy command (good old cp) that supports the ability to use the cloning feature of APFS by using the -c flag.
I have file A that's in two places and I run this.

I modify A_0. Does this modify A_1 as well or just kind of reify the new state of A_0 while leaving A_1 untouched?

What jumped out to me:

> Finally, at WWDC 2017, Apple announced Apple File System (APFS) for macOS (after secretly test-converting everyone’s iPhones to APFS and then reverting them back to HFS+ as part of an earlier iOS 10.x update in one of the most audacious technological gambits in history).

How can you revert a FS change like that if it goes south? You'd certainly exercise the code well but also it seems like you wouldn't be able to back out of it if something was wrong.

Start with a story, narrow it down to a problem and show how your solution magically solves that problem. Such a fine example of GREAT marketing.
I gave it a try on my massive folder of NodeJS projects but it only found 1GB of savings on a 8.1GB folder.

I then tried again including my user home folder (731K files, 127K folders, 2755 eligible files) to hopefully catch more savings and I only ended up at 1.3GB of savings (300MB more than just what was in the NodeJS folders.)

I tried to scan System and Library but it refused to do so because of permission issues.

I think the fact that I use pnpm for my package manager has made my disk space usage already pretty near optimal.

Oh well. Neat idea. But the current price is too high to justify this. Also I would want it as a background process that runs once a month or something.

I wrote a similar (but simpler) script which would replace a file by a hardlink if it has the same content.

My main motivation was for the packages of Python virtual envs, where I often have similar packages installed, and even if versions are different, many files would still match. Some of the packages are quite huge, e.g. Numpy, PyTorch, TensorFlow, etc. I got quite some disk space savings from this.

https://github.com/albertz/system-tools/blob/master/bin/merg...

On Windows there is "Dev Drive" which I believe does a similar "copy-on-write" -thing.

If it works it's a no-brainer so why isn't it the default?

https://learn.microsoft.com/en-us/windows/dev-drive/#dev-dri...

Would be nice if git could make use of this on macOS.

Each worktree I usually work on is several gigs of (mostly) identical files.

Unfortunately the source files are often deep in a compressed git pack file, so you can't de-duplicate that.

(Of course, the bigger problem is the build artefacts on each branch, which are like 12G per debug/release per product, but they often diverge for boring reasons.)

Was pleasantly surprised to see that this is John Siracusa - the original GOAT when it comes to macOS release articles on Ars.
> Like all my apps, Hyperspace is a bit difficult to explain. I’ve attempted to do so, at length, in the Hyperspace documentation. I hope it makes enough sense to enough people that it will be a useful addition to the Mac ecosystem.

Am I missing something, or isn't it a "file de-duplicator" with a nice UI/UX? Sounds pretty simple to describe, and tells you why it's useful with just two words.

Oh wow, what a funny coincidence. I hadn't visited the site in a couple of years but someone linked me "Front and Center" yesterday, so I saw the icon for this app and had no clue it had only appeared there maybe hours earlier.

The idea is not new, of course, and I've written one of these (for Linux, with hardlinks) years ago but in the end just deleted all the duplicate files in my mp3 collection and didn't touch the rest of the files on the disk, because not a lot of size was reclaimed.

I wonder for whom this really saves a lot of space. (I saw someone mentioning node_modules, had to chuckle there).

But today I learned about this APFS feature, nice.

What are examples of files that make up the "dozens of gigabytes" of duplicated data?
Interesting idea, and I like the idea of people getting paid for making useful things.

Also, I get a data security itch having a random piece of software from the internet scan every file on an HD, particularly on a work machine where some lawyers might care about what's reading your hard drive. It would be nice if it was open source, so you could see what it's doing.

In earlier episodes of ATP when they were musing on possible names, one listener suggested the frankly amazing "Dupe Nukem". I get that this is a potential IP problem, which is why John didn't use it, but surely Duke Nukem is not a zealously-defended brand in 2025. I think interest in that particular name has been stone dead for a while now.
I’ve experimented with reflinks and other APFS operations.

Here’s a question though: how does this work with transparently compressed files on APFS?

In my past experience, using reflinks is fine and using transparent compression is fine, but combining them leads to hard-to-debug file corruption.

Wasn't able to use it on a few directories I tried as they were inside iCloud Drive.
This is cool!

Wait a minute, what happens to copies on different physical drives. Are they cloned too?

Hopefully doesn’t have similar bug like jdupes did

https://web.archive.org/web/20210506130542/https://github.co...

My personal head canon is that Steve Jobs personally cancelled ZFS in OSX because Jonathan Schwartz prematurely announced it.
Is this the dedup function provided by other FS?
On a related note: are there any utilities that can measure disk usage of a folder taking (APFS) cloned files into account?
Does it preserve all metadata, extended attributes, and alternate streams/named forks?
What are the potential risks or problems of such conversion of duplicates into APFS clones?
What would an equivalent tool be on linux? I guess it depends on the filesystem?
OmniDiskSweeper (I know, not exactly the same thing, but still...)
Any way it can be built for 14? It requires macOS 15.
Wish John went with the name superdeduper :/ :P
TL;DR: He wrote an OS X dedup app which finds files with the same contents and tells the filesystem that their contents are identical, so it can save space (using copy-on-write features).

He points out its dangerous but could be worth it cause space savings.

I wonder if the implementation is using a hash only or does an additional step to actually compare the contents to avoid hash collision issues.

It's not open source, so we'll never know. He chose a pay model instead.

Also, some files might not be identical but have identical blocks. Something that could be explored too. Other filesystems have that either in their tooling or do it online or both.

What's the difference with jdupes?
In my experience, Macs use up a ridiculous amount of "System" storage for no reason that users can't delete. I've grown tired of family members asking me to help them free up storage that I can't even find. That's the major issue from what I've seen; unless this app prevents apple deliberately eating up 50%+ of the storage space of a machine, this doesn't do much for the people I know.
;( requires macos 15
John is a the legend.
Many comments here offering similar solutions based on hardlinks or symlinks.

This uses a specific feature of APFS that allows the creation of copy-on-write clones. [1] If a clone is written to, then it is copied on demand and the original file is unmodified. This is distinct from the behavior of hardlinks or symlinks.

[1] https://en.wikipedia.org/wiki/Apple_File_System#Clones

Downloaded. Ran it. Tells me "900" files can be cleaned. No summary, no list. But I was at least asked to buy the app. Why would I buy the app if I have no idea if it'll help?
https://github.com/pkolaczk/fclones can do the same thing, and it's perfectly free and open source. terminal based though