{"id":51918,"date":"2026-05-14T14:38:26","date_gmt":"2026-05-14T18:38:26","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=51918"},"modified":"2026-05-15T11:11:15","modified_gmt":"2026-05-15T15:11:15","slug":"apfs-folder-clones","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2026\/05\/14\/apfs-folder-clones\/","title":{"rendered":"APFS Folder Clones"},"content":{"rendered":"<p><a href=\"https:\/\/mastodon.social\/@palmin\/116566710077655881\">Anders Borum<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@palmin\/116566710077655881\">\n<p>After my experiments with APFS cloning, I made a <a href=\"https:\/\/www.icloud.com\/shortcuts\/ff7cd3540b1b4d94bd95beb6fe08dd09\">Quick Action shortcut<\/a> for Finder that&rsquo;s much faster than Duplicate or &ldquo;cp -c -R&rdquo;, both of which clone files individually instead of the whole tree in one go.<\/p>\n<\/blockquote>\n<p>The regular file copying APIs also give you folders full of file clones rather than a directory clone. His shortcut runs a Python script:<\/p>\n<blockquote cite=\"https:\/\/www.icloud.com\/shortcuts\/ff7cd3540b1b4d94bd95beb6fe08dd09\"><p>The clone is made with the macOS clonefile(2) syscall, invoked\n  directly through ctypes. clonefile asks APFS to create a new inode\n  that shares the source&rsquo;s data extents &mdash; no bytes are copied up\n  front, the new tree just points at the same disk blocks. The two\n  trees diverge lazily: only blocks that are later modified in one\n  side get their own physical storage (copy-on-write).<\/p><\/blockquote>\n<p>However, it&rsquo;s not clear to me what the benefit is. Aside from somehow being faster, it sounds like you end up with the same structure. The <a href=\"https:\/\/keith.github.io\/xcode-man-pages\/clonefile.2.html\">clonefile(2)<\/a> man page says:<\/p>\n<blockquote cite=\"https:\/\/keith.github.io\/xcode-man-pages\/clonefile.2.html\"><p>If <code>src<\/code> names a directory, the directory hierarchy is cloned as if each item was cloned individually. However, the use of <tt>clonefile(2)<\/tt> to clone directory hierarchies is strongly discouraged. Use <tt>copyfile(3)<\/tt>\ninstead for copying directories.<\/p>\n<\/blockquote>\n\n<p>I don&rsquo;t think APFS really supports directory clones except at the snapshot level.<\/p>\n\n<p>See also: <a href=\"https:\/\/apple.stackexchange.com\/questions\/322036\/is-it-possible-to-clone-directories-in-apfs\">Ask Different<\/a>, <a href=\"https:\/\/eclecticlight.co\/2025\/04\/07\/how-robust-are-apfs-clone-and-sparse-files\/\">Howard Oakely<\/a>.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/05\/05\/hyperspace-1-3\/\">Hyperspace 1.3<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/01\/14\/aliases-hard-links-symlinks-and-copies-in-mojaves-apfs\/\">Aliases, Hard Links, Symlinks, and Copies in Mojave&rsquo;s APFS<\/a><\/li>\n<\/ul>\n\n<p id=\"apfs-folder-clones-update-2026-05-15\">Update (<a href=\"#apfs-folder-clones-update-2026-05-15\">2026-05-15<\/a>): <a href=\"https:\/\/developer.apple.com\/forums\/thread\/784446\">Kevin Elliott<\/a> (via <a href=\"https:\/\/mjtsai.com\/blog\/2026\/05\/14\/apfs-folder-clones\/#comment-4411210\">Frizlab<\/a>):<\/p>\n<blockquote cite=\"https:\/\/developer.apple.com\/forums\/thread\/784446\">\n<p>[You] can basically think of cloning a directory as doing two things:<\/p>\n<ol><li>\n<p>Pushing the copy operation into kernel, avoiding the syscall overhead of directory iteration, creation, and individual clonefile calls.<\/p>\n<\/li><li>\n<p>Preventing all changes to the source hierarchy while the operation is in progress, making the process atomic.<\/p>\n<\/li><\/ol>\n<p>That second point is what makes this potentially dangerous as, in the worst case, you could theoretically panic the kernel by stalling all activity on critical locations long enough that the kernel \"gives up\" and panics.<\/p>\n<p><\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Anders Borum: After my experiments with APFS cloning, I made a Quick Action shortcut for Finder that&rsquo;s much faster than Duplicate or &ldquo;cp -c -R&rdquo;, both of which clone files individually instead of the whole tree in one go. The regular file copying APIs also give you folders full of file clones rather than a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2026-05-14T18:38:29Z","apple_news_api_id":"c76458ce-f7bb-4f7a-b956-703effec1194","apple_news_api_modified_at":"2026-05-15T15:11:18Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/Ax2RYzve7T3q5VnA-_-wRlA","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[1395,30,2742,232,1686],"class_list":["post-51918","post","type-post","status-publish","format-standard","hentry","category-technology","tag-apple-file-system-apfs","tag-mac","tag-macos-tahoe-26","tag-python","tag-shortcuts"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/51918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=51918"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/51918\/revisions"}],"predecessor-version":[{"id":51923,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/51918\/revisions\/51923"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=51918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=51918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=51918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}