118

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?

11 Answers 11

76

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.

6
  • 17
    Mac OS X 10.6 uses a BSD tar by default but also ships with a gnutar at /usr/bin/gnutar.
    – Ned Deily
    Aug 3, 2011 at 22:03
  • @Ned. Thx. that's good info. Aug 4, 2011 at 0:31
  • 23
    FYI : /usr/bin/gnutar is not shipped anymore with Mac OS X (at least as of Mavericks)
    – foobar
    Nov 27, 2013 at 13:52
  • 1
    If using MacPorts, you can also just put /opt/local/libexec/gnubin/ at the top of your PATH rather than removing anything from /usr/bin or manually creating symlinks.
    – Lorrin
    Feb 13, 2017 at 22:57
  • 2
    If using Homebrew: brew install gnu-tar
    – TrinitronX
    Oct 7, 2019 at 21:19
71

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

2
  • 5
    No need to unlink anymore, as brew instructs, you can just add this to your PATH in .bashrc (or your equivalent): PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" Jun 10, 2015 at 16:13
  • 1
    Or just create a tar link in /usr/local/bin by cd /usr/local/bin ; ln -s gtar tar - possibly the simplest option
    – Karthik T
    Apr 19, 2016 at 3:43
33

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
1
  • 7
    this should be the right answer because it doesn't involve installing an entirely new tool for the sake of suppressing a single warning.
    – c z
    May 22, 2017 at 12:53
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.

7
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
2
  • Sadly, this does not appear to stop the extended header keyword warnings when untarring with gnutar.
    – JJC
    Sep 21, 2016 at 14:27
  • Neither of these seems to work on Yosemite (tar --version indicates bsdtar 2.8.3 - libarchive 2.8.3). Also I need a dash before cf in the latter case.
    – tripleee
    Jan 31, 2017 at 12:04
4

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
4
  • 1
    Why in /etc/hosts? /etc/hosts is for host/IP mapping, right?
    – BenjiWiebe
    Feb 21, 2013 at 16:47
  • 1
    what @BenjiWiebe said. The even odder bit is editing /etc/hosts. I think you meant ~/.bashrc Feb 21, 2013 at 17:57
  • 2
    On OS X, .bashrc isn't loaded for Terminal sessions. You need .bash_profile, since a login shell is started with a new Terminal window. /cc @BenjiWiebe
    – slhck
    Feb 21, 2013 at 19:32
  • Correct :-) I was also working in /etc/hosts at that time so it spewed onto the keyboard. Good catch
    – Du3
    Feb 25, 2013 at 9:52
3

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.

1

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

tar cfz yoyodyne.tgz --no-xattrs /tmp/john_bigbootie/*
0

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!

3
  • 1
    That's one way. I solved the GNU/BSD issue more comprehensively in github.com/ddopson/dotfiles. I have ~/bin/coreutils early in the path and there's small shims in there like github.com/ddopson/dotfiles/blob/master/bin/coreutils/tar that pick the correct executable based on linux vs Mac and if the COREUTILS environment variable is set Feb 8, 2013 at 2:24
  • You might want to modify your instructions to tell people to check for the existence of /usr/bin/gnutar before moving their working tar. Newbies can find this using google and not know how to un-break their system.
    – msouth
    May 15, 2014 at 15:18
  • 1
    That's probably not a good idea, for a couple of reasons. 1) Now Apple packages don't know where to find the native tar, the tar that knows how to handle Apple file attributes. 2) If you must use GNU tar, the proper place to put it is ahead in your search path, like /usr/local/bin, or something, and 3) It's probably safer still to call the foreign tar program gnutar to avoid confusing software expecting a Mac to act like a Mac. $0.02. -Erik Sep 12, 2017 at 14:42
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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .