The Computer Oracle

Linux / OS X tar incompatibility – tarballs created on OS X give errors when untarred in Linux

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Bleepage Open

--

Chapters
00:00 Linux / Os X Tar Incompatibility – Tarballs Created On Os X Give Errors When Untarred In Linux
01:15 Accepted Answer Score 76
01:31 Answer 2 Score 71
02:03 Answer 3 Score 33
02:27 Answer 4 Score 10
02:54 Answer 5 Score 7
03:52 Thank you

--

Full question
https://superuser.com/questions/318809/l...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #macos #commandline #tar

#avk47



ACCEPTED ANSWER

Score 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.




ANSWER 2

Score 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




ANSWER 3

Score 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



ANSWER 4

Score 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.




ANSWER 5

Score 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