Why COPYFILE_DISABLE Does Nothing on Linux

We set it against a Mac tar command's Linux equivalent, twice, and diffed the archives byte for byte. Here are the five lines of libarchive source that explain why nothing changed.

By Ram Velmurugan · Founder & Lead Developer, 1dot.ai

Quick X Folder Preview · TroubleshootingTested and checked live Nov 24, 2026·9 min read
Quick answer: COPYFILE_DISABLE=1 is read by bsdtar's own startup code, and only in builds where Apple's copyfile.h exists. GNU tar never reads it, and a Linux build of bsdtar compiles the check out, so setting the variable there has nothing to disable. We proved it with matching md5sum output below. If you need a clean archive for a Linux target, run the variable on the Mac that builds it, or use --exclude='._*' --exclude='__MACOSX', which works identically on both platforms.

Editorial note: 1dot.ai makes Quick X Folder Preview, a folder and archive preview app for Mac mentioned near the end of this guide. It plays no role in tar, CI pipelines, or anything tested below. Every command in this post was actually run in a Linux container (Ubuntu 24.04), not on a Mac, since that is the platform this problem actually shows up on. Where a claim is specific to macOS, we cite Apple's own source code and documentation rather than assume it from the Linux side. This is a companion piece to our earlier post on the related __MACOSX folder and ._ files in zip archives, which covers the zip-specific version of the same underlying metadata. Checked live on November 24, 2026.

The Short Version

Somewhere a Stack Overflow answer or a blog post told you that export COPYFILE_DISABLE=1 before a tar command stops macOS from stuffing resource forks and Finder metadata into the archive. That advice is correct, on a Mac. A lot of the places people actually hit this problem aren't Macs. A GitHub Actions runner unpacking a release tarball, a Docker build stage copying in a project checked out from a Mac, a Linux box receiving a tarball over rsync, all of these are running GNU tar or a Linux build of bsdtar, and the variable does nothing there. We set it against both, twice each, and compared the resulting archives byte for byte.

What COPYFILE_DISABLE Actually Does, on a Mac

macOS's /usr/bin/tar isn't GNU tar. It's bsdtar, built on the libarchive project. Apple first added the copyfile handling as its own patch to libarchive (the copyfile.patch in Apple's libarchive-13.1 source), and the same logic now lives in upstream libarchive. By default, bsdtar sets a flag named ARCHIVE_READDISK_MAC_COPYFILE, which makes it call Apple's copyfile() API for each file it archives. That API is what reads a file's resource fork, Finder info and extended attributes off disk and packs them into a ._ entry. If COPYFILE_DISABLE is set at startup, bsdtar clears the flag and archives the plain data alone. The --no-mac-metadata option does the same, and --disable-copyfile is an alias for it.

The environment check only compiles where Apple's copyfile.h header exists, which means macOS. On Linux, copyfile() is not a function that exists to call, so there is nothing for the variable to switch off.

We Tested It on Linux, Twice Each

This session has no Mac, which is exactly the point: it has what a Linux CI runner has. We installed libarchive-tools for bsdtar (Ubuntu 24.04 ships GNU tar 1.35 by default), created a file with one real extended attribute set via setfattr, and archived it four ways on November 24, 2026:

$ echo "hello from a real file" > report.txt
$ setfattr -n user.test -v demo-value report.txt

$ tar -cf plain.tar report.txt
$ md5sum plain.tar
f433c52e9f093c52272643e65d63a3eb  plain.tar

$ COPYFILE_DISABLE=1 tar -cf copyfile.tar report.txt
$ md5sum copyfile.tar
f433c52e9f093c52272643e65d63a3eb  copyfile.tar
$ cmp plain.tar copyfile.tar && echo "byte-identical"
byte-identical

$ bsdtar -cf bsd_plain.tar report.txt
$ md5sum bsd_plain.tar
f8389e66f73d58d7399ec6912e1d3202  bsd_plain.tar

$ COPYFILE_DISABLE=1 bsdtar -cf bsd_copyfile.tar report.txt
$ md5sum bsd_copyfile.tar
f8389e66f73d58d7399ec6912e1d3202  bsd_copyfile.tar
$ cmp bsd_plain.tar bsd_copyfile.tar && echo "byte-identical"
byte-identical

Both tools, with and without the variable, every single byte the same. We went one step further and checked whether --disable-copyfile is even a flag this Linux build of bsdtar recognizes, rather than one it silently ignores, by comparing it against a flag we made up:

$ bsdtar --disable-copyfile -cf disable_test.tar report.txt
$ md5sum disable_test.tar bsd_plain.tar
f8389e66f73d58d7399ec6912e1d3202  disable_test.tar
f8389e66f73d58d7399ec6912e1d3202  bsd_plain.tar

$ bsdtar --totally-fake-option -cf x.tar report.txt
bsdtar: Option --totally-fake-option is not supported
$ echo "exit: $?"
exit: 1

That answers a question we had going in: is --disable-copyfile compiled out of the Linux build entirely, or is it present but inert? It's present. bsdtar parses it and accepts it (exit 0, no error), which a genuinely unsupported option does not get. In upstream libarchive's tar/cmdline.c it is listed as an alias of --no-mac-metadata. On Linux it clears a flag that libarchive never acts on, so the archive comes out unchanged.

Why It's a No-Op Outside macOS

The whole answer is five lines in upstream libarchive's tar/bsdtar.c, read on November 24, 2026:

/*
 * Enable Mac OS "copyfile()" extension by default.
 * This has no effect on other platforms.
 */
bsdtar->readdisk_flags |= ARCHIVE_READDISK_MAC_COPYFILE;
#ifdef COPYFILE_DISABLE_VAR
if (getenv(COPYFILE_DISABLE_VAR))
	bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_MAC_COPYFILE;
#endif

COPYFILE_DISABLE_VAR is defined in Apple's copyfile.h, which bsdtar only includes when the build finds that header. On Linux the header does not exist, the macro is never defined, and the getenv call is compiled out. The flag it would clear does nothing there anyway, as the comment says. GNU tar has no equivalent code at all.

There's a second layer to this worth knowing about if you ever go looking for the check yourself. We read the current copyfile.c source directly from Apple's copyfile project on November 24, 2026, expecting to find the environment-variable check inside the copyfile() library function itself. It's there, but it's dead code:

#if 0
	/* Temporarily disabled */
	if (getenv(COPYFILE_DISABLE_VAR) != NULL)
	{
		copyfile_debug(1, "copyfile disabled");
		return 2;
	}
#endif

That block sits inside copyfile_preamble(), wrapped in a standard C #if 0, which means the compiler skips it entirely. The library function that does the actual file copying on macOS doesn't act on COPYFILE_DISABLE at all, by design, with a comment that says so. The variable only works at all because bsdtar implements its own separate check, in its own command-line code, rather than relying on the shared library to self-disable. One more reason the behavior is specific to how bsdtar was built, not something baked generically into "copying files on a Mac."

The Real Difference: Which xattr Namespace Each Tool Writes

COPYFILE_DISABLE is the wrong variable for the problem most Linux users actually run into, which isn't resource forks at all. It's a mismatch in how GNU tar and bsdtar each store ordinary POSIX extended attributes, like the user.test attribute we set above. We archived the same file with GNU tar's --xattrs flag and with bsdtar's default behavior, then grepped the raw archive bytes for the pax header keywords each one wrote:

ToolPax keyword writtenValue stored
GNU tar 1.35, --xattrsSCHILY.xattr.user.testdemo-value (raw)
bsdtar 3.7.2 (libarchive 3.7.2), defaultLIBARCHIVE.xattr.user.testZGVtby12YWx1ZQ (base64)
bsdtar 3.7.2 (libarchive 3.7.2), defaultSCHILY.xattr.user.testdemo-value (raw, written again)

GNU tar writes one keyword, SCHILY.xattr.*, a namespace that comes from Jörg Schilling's star archiver and was adopted into GNU tar later. bsdtar's default behavior writes the attribute twice over, once under its own LIBARCHIVE.xattr.* keyword with the value base64-encoded, and again under SCHILY.xattr.* with the raw value, which is bsdtar covering both readers at once. Neither keyword is related to COPYFILE_DISABLE or to resource forks. If a build script somewhere compares archives across a Mac and a Linux box and finds different-looking pax headers for the same files, this namespace mismatch, not Apple metadata, is usually why.

Where This Actually Bites: CI and Docker

The failure mode we see described most often: a developer on a Mac zips or tars a project, uploads it, and a Linux CI job or a Docker build stage unpacks it with ._ files or a __MACOSX folder still inside, sometimes breaking a build step that globs * and trips over an unexpected file. The fix almost never lands because whoever is debugging it is staring at the Linux side, where the archive already exists, and tries setting COPYFILE_DISABLE=1 on the machine doing the unpacking. That machine was never going to react to it. The variable only matters on the machine that originally builds the archive.

The debugging trap
If you're troubleshooting this from a GitHub Actions log, a Dockerfile RUN step, or a Linux build server, you are looking at the wrong end of the pipeline to set this variable. Fix it where the tarball is created, or filter it out at extraction time instead, covered next.

What Actually Works

Run the variable where it actually works, on the Mac

If a Mac is the machine building the archive, COPYFILE_DISABLE=1 tar -czf archive.tar.gz folder is the real, documented fix, and libarchive's own bsdtar.c is the source for why it works there: on a Mac, bsdtar reads the variable at startup and clears the flag that makes it call Apple's copyfile() API for each file, so that run archives plain data only. The same effect is available as a flag, --no-mac-metadata, which --disable-copyfile is an alias for. The mistake isn't the variable. It's setting it on the wrong machine, usually the Linux CI runner that unpacks the archive after a Mac already built it.

Free, zero new tools

Use --exclude instead, which works on both platforms

tar --exclude='._*' --exclude='__MACOSX' -czf archive.tar.gz folder is a plain tar feature with no dependency on Apple's copyfile integration, so it behaves the same on macOS, Linux, and inside a container. We ran it against a folder seeded with a ._report.txt sidecar and a __MACOSX directory on this session's own Linux container: both patterns were excluded, confirmed by listing the resulting archive afterward.

Free, portable, one command

Clean a tarball you already received

GNU tar can delete entries in place, but only from an uncompressed archive: tar --delete -f old.tar 'myproject/._report.txt' worked in our test. Point it at a .tar.gz and GNU tar 1.35 stops with "Cannot update compressed archives", and bsdtar has no delete option at all. For a compressed tarball, the reliable path is tar --exclude='._*' --exclude='__MACOSX' -xzf old.tar.gz -C clean_dir to extract everything except the junk, then re-archive clean_dir if you need to pass it along again.

Free, no original folder needed

The exclude pattern, tested

We seeded a folder with a real file, a ._report.txt sidecar, and a __MACOSX directory, matching what a Mac-built archive would contain, then ran the exclude flags against it on November 24, 2026:

$ tar --exclude='._*' --exclude='__MACOSX' -czf clean.tar.gz myproject
$ tar -tzf clean.tar.gz
myproject/
myproject/report.txt

Both the sidecar and the directory were gone from the listing, with no COPYFILE_DISABLE involved at all, which is the point: --exclude is a plain pattern match against filenames, something GNU tar and bsdtar both implement the same way on every platform, so it behaves identically whether it runs on the Mac that built the project or the Linux job that consumes it.

Does This Affect Our Own Apps?

Not directly, and we would rather be specific than vague about it. Quick X Folder Preview lets you look inside an archive's contents on the space bar before you extract it, which would show you a stray ._ file sitting in there, but it doesn't run inside a build pipeline or touch tar at all. Files Magic AI's System Cleaner is built around a different kind of clutter, unused apps, old installers, and developer caches like Xcode and Gradle build folders on your own Mac, not the contents of an archive a CI job assembles on a remote server. If your actual problem is a Linux job choking on Mac metadata, the tar flags above are the fix, not either of our products.

Sources & Further Reading

The disable mechanism, from the source: upstream libarchive's tar/bsdtar.c (the COPYFILE_DISABLE_VAR check) and tar/cmdline.c (--disable-copyfile as an alias of --no-mac-metadata), Apple's original libarchive copyfile patch, and the copyfile project's copyfile.c, where the equivalent check inside the shared library itself sits in a disabled #if 0 block. All read directly on November 24, 2026.

GNU tar's extended-attribute handling: the GNU tar manual's Extended File Attributes section, which documents --xattrs and the pax archive format it implies.

Independent confirmation that macOS's own tar honors the variable: CMake issue #16168, discussing exactly this behavior on macOS from the build-tooling side.

Version banners quoted in this post were read directly from tar --version, bsdtar --version, and the libarchive-tools package (bsdtar 3.7.2, libarchive 3.7.2) installed in this session's own Ubuntu 24.04 container on November 24, 2026.

Our related coverage: what ._ files and the __MACOSX folder actually are, and how to stop them in zip archives, and previewing zip contents on Mac without extracting.

Frequently Asked Questions

Why does COPYFILE_DISABLE=1 work on macOS but not on Linux?
Because the check lives in bsdtar's own startup code and only compiles where Apple's copyfile.h exists. In upstream libarchive's tar/bsdtar.c, bsdtar turns on a flag called ARCHIVE_READDISK_MAC_COPYFILE by default, then clears it if getenv(COPYFILE_DISABLE_VAR) returns anything. That getenv call sits inside #ifdef COPYFILE_DISABLE_VAR, a macro that only Apple's copyfile.h defines, so a Linux build never even reads the variable. The flag itself is also ignored off macOS: the source comment next to it says it "has no effect on other platforms." We confirmed the result directly: identical md5 hashes with and without the variable set, further down.
Does setting COPYFILE_DISABLE in a GitHub Actions or Docker Linux runner do anything?
No. GitHub-hosted Linux runners and the vast majority of Docker base images ship GNU tar, and some also carry libarchive-based bsdtar through a package like libarchive-tools. We set COPYFILE_DISABLE=1 against both on Ubuntu 24.04 and got byte-identical archives to leaving it unset, both times. If a tarball built on a Mac still carries ._ files or a __MACOSX folder by the time it reaches a Linux CI job, the fix has to happen on the Mac side, before the tar command runs there, not in the Linux job that unpacks it.
What is the actual fix if I need a clean tarball from a Mac, for a Linux target?
Run COPYFILE_DISABLE=1 tar -czf archive.tar.gz folder on the Mac that creates the archive, which is the one place it actually does something. If the archive already exists and you only have Linux to work with, extract it, delete anything matching ._* and __MACOSX, and re-tar on Linux. A one-line filter at extract time also works: tar --exclude='._*' --exclude='__MACOSX' -xf archive.tar on either platform, since --exclude is a portable tar feature that does not depend on Apple's copyfile integration at all.
Does GNU tar and bsdtar store extended attributes the same way?
No, and this trips up cross-platform diffing. We set one extended attribute on a file and archived it both ways: GNU tar's --xattrs wrote a single SCHILY.xattr.user.test pax header, a keyword namespace that originated in Jörg Schilling's star. bsdtar's default behavior wrote two separate pax headers for the same attribute, SCHILY.xattr.user.test with the raw value and LIBARCHIVE.xattr.user.test with the value base64-encoded, so a reader that only understands one namespace still finds the data under the other. Neither of those keywords has anything to do with COPYFILE_DISABLE; they store ordinary POSIX extended attributes, not Apple's resource-fork and Finder-metadata format.
Is this the same thing as the __MACOSX folder in zip files?
Related, but not identical, and worth separating. Apple's ditto documentation describes __MACOSX as something ditto's PKZip-creation path writes deliberately, covered in our companion post on zip archives. tar on macOS handles the same underlying AppleDouble metadata differently: bsdtar calls copyfile() to pack a file's resource fork and extended attributes into a ._ entry stored right next to that file in the archive (unless COPYFILE_DISABLE stops it), rather than gathering them in a separate __MACOSX folder. Same root cause, Apple's AppleDouble metadata model, two different tools handling it two different ways.
Does Files Magic AI or Quick X Folder Preview fix any of this?
No, and we would rather say that plainly than imply otherwise. Neither product touches tar, CI pipelines, or extended attributes. Quick X Folder Preview previews what is inside an archive on the space bar before you extract it, which would at least show you a stray ._ file or a __MACOSX folder before you committed to opening the archive, but it does not strip anything out or run in a build pipeline. Files Magic AI's System Cleaner targets unused apps, old installers, and developer caches like Xcode and Gradle build folders on your own Mac, a completely different job from cleaning a tarball a CI job just built. For this exact problem, the tar flag and exclude patterns covered below are the actual fix.

The Bottom Line

COPYFILE_DISABLE=1 is real, documented, and genuinely useful, on the one platform where the code that reads it was ever compiled in. We set it against GNU tar and bsdtar on Linux, twice each, and got byte-identical archives both times, which is about as directly as this can be shown. If a tarball built on a Mac is carrying junk into a Linux CI job, set the variable on the Mac, or use --exclude='._*' --exclude='__MACOSX', which doesn't care which platform runs it.


Looking for more Mac troubleshooting guides? Read what ._ files and __MACOSX actually are in a zip archive, see our guide to previewing zip contents before you extract anything, browse every 1dot.ai guide, or check Quick X Folder Preview's product page.

Want to See Inside an Archive Before You Open It?

Quick X Folder Preview adds 13 Quick Look extensions to the space bar, notarized by Apple. Free for 14 days, then $4.99 once for a lifetime license.

Try It FreeRead More Guides