123

When I tar up files on my Macbook and untar them in Linux, I repeatedly get the following warnings/errors:


 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Ignoring unknown extended header keyword `SCHILY.dev'
 tar: Ignoring unknown extended header keyword `SCHILY.ino'
 tar: Ignoring unknown extended header keyword `SCHILY.nlink'
 tar: Error exit delayed from previous errors

Fortunately, this does NOT affect the files stored in the archive, which are restored perfectly. However, it does cause problems in a number of scenarios, especially when dealing with build processes where the non-zero failure code returned by 'tar' causes builds and installs to stop unnecessarily.

How can I get OS X to build tar files that play nicely with the rest of the Linux world?

Also, for bonus points, there exists a publicly distributed tar file with these issues. Is there any way to get Linux to handle the tar file gracefully without changing the way it was originally compressed?

slhck
  • 235,242
Dave Dopson
  • 1,325

12 Answers12

78

I Googled for the error message and it seems like a BSD tar vs. GNU tar issue.

Install GNU tar if you can on Mac OS and use that to create the tar.

Giacomo1968
  • 58,727
holygeek
  • 1,069
74

If you are using Mavericks or newer, then gnutar is no longer included by default.

The work around, if you use homebrew, is to execute the following:

brew install gnu-tar

You can then use the command gtar for linux compatability.


If you want to replace tar with gtar, simply replace the symlink

tar --version
ll `which tar`
sudo unlink `which tar`
sudo ln -s `which gtar` /usr/bin/tar
tar --version

To restore the original tar provided with Mac Os X, run the above commands but replace which gtar with which bsdtar

Source:
https://github.com/jordansissel/fpm/issues/576

spuder
  • 10,135
34

GNU tar doesn't like some of the optional information the default OSX BSD tar includes.

GNU tar will let you suppress those warnings with the option:

--warning=no-unknown-keyword

See: https://www.gnu.org/software/tar/manual/html_section/tar_27.html

Note that BSD tar doesn't support that flag so if you need to run the same unpacking code on all platforms you can use something like:

isGnuTar=$(tar --version | grep -q 'gnu')
if [ $? -eq 0 ]
then
    echo "Detected GNU tar"
    tar --warning=no-unknown-keyword -zxf my.tar.gz
else
    tar -zxf my.tar.gz
fi
Chris
  • 441
10

To extract the tar file properly without any errors on a Linux system you could use bsdtar.

sudo apt-get install bsdtar

Then use as normal.

bsdtar -xvf file.tar where file.tar is the tar file you want to extract.

Source: https://bugs.launchpad.net/ubuntu/+source/tar/+bug/129314

Alternatively you can also use GNOME file roller.

olfek
  • 289
8
COPYFILE_DISABLE=1 tar cf filename.tar

or

tar --disable-copyfile cf filename.tar

This is the least discoverable feature of tar on OS X that I am personally aware of.

See also Why do I get files like ._foo in my tarball on OS X?


Edit: it looks like this might only stop the creation of the unwanted ._foo-type files, it doesn't stop the header creation (at least on Yosemite/10.10); thanks commenters for pointing it out. However, (for the bonus points:) you can gracefully handle such tarballs by extracting them like this:

tar xf filename.tar --pax-option=delete=SCHILY.*,delete=LIBARCHIVE.*

This worked using gnu tar 1.15.1, which is pretty old! Alternatively, you can use pax instead, which (for me) throws the extra info into a PaxHeader directory, but at least exits without error:

pax -rf filename.tar
4

Use the --no-xattrs option when creating the archive:

tar cfz yoyodyne.tgz --no-xattrs /tmp/john_bigbootie/*
aqn
  • 141
3

MacOSX comes with gnutar already. If you want a quick and dirty solution add this to ~/.bash_profile

alias tar='gnutar'

and run source ~/.bash_profile to update

Additionally, OSX ships with both GNU and BSD tar. So you can also unlink the ref of tar from bsd to gnu:

sudo unlink /usr/bin/tar;
sudo ln -s /usr/bin/gnutar /usr/bin/tar
Du3
  • 139
2

Thank you. This thread was very useful. If you are using MacPorts here is a quick howto:

sudo port install gnutar

sudo ln -s /usr/local/opt/gnu-tar/libexec/gnubin/tar /usr/bin/gnutar

sudo ln -s /opt/local/libexec/gnubin/tar /usr/bin/gnutar

Add the following line to /Users/[yourname]/.profile

alias tar='/opt/local/libexec/gnubin/tar'

Quit und and restart your Terminal window.

BINROTH
  • 179
0

On MAC OSX install gnu-tar

brew install gnu-tar

then create your linux compatible tar with:

gtar -c -f your_tar_file files

Or you can create your archive with pax format

tar -c --format pax -f your_tar_file files
msadek
  • 49
0

Replacing macOS tar with GNU tar in 2024:

  1. In terminal:

    brew install gnu-tar

  2. In ~/.bashrc

# Apple Silicon
export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"

Intel

export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"

Start a new shell and verify:

> tar --version
tar (GNU tar) 1.35
Copyright (C) 2023 Free Software Foundation, Inc.
Pavel Vlasov
  • 1,931
0

Okay, I used Google search, but top three link confirmed what I suspected

  1. Bug in your tar AND/OR
  2. Incompatibility between the two tar utilities
    See this link. There someone reports that "Using "bsdtar -xvf" worked."

Edit: You are on Mac system, I thought other way round. You will need to use gnutar, it should be installed already, if not get it installed. Of course, you can look at other links by searching yourself.

Giacomo1968
  • 58,727
wadkar
  • 143
-1

Yea, Mac's built-in tar binary adds a bunch of extra stuff that CentOS doesn't like. To fix this do the following:

sudo mv /usr/bin/tar /usr/bin/darwintar
sudo ln -s /usr/bin/gnutar /usr/bin/tar
ls -l /usr/bin/tar

Hope that helps!