Partially recovering damaged tar files in Mac OS X


Archive Utility having trouble with a malformed/damaged tar file
Archive Utility having trouble with a malformed/damaged tar file

Okay enough political nonsense, back to writing about technology and software!

Unlike zip or proprietary rar files, in true "do one thing and do it well" Unix style, most Unix-like file compressors (such as bzip2, rzip or gzip) only compress one file at a time. An intermediate container format is needed if multiple files in one compressed archive are needed, the most common of which is the Tape Archive file/tarball or tar.

Archive Utility

Mac OS X's Archive Utility (which you invoke from the Finder) has native support for tar, but I'm surprised by the number of times I see the error message above after double clicking and attempting to open one. Usually this is a result of a malformed or broken tar file, but the nature of tar files is that generally some files can be salvaged. The Finder refuses to do this, which worries me. How many GUI proficient Mac users throw away tar files that they could salvage at least some files out of?

The solution is a quick trip to the Terminal and using the cd command (same way as DOS) to navigate to the folder where the tar file you're having trouble with is located. Then enter:

% tar xvf [FILENAME].tar

In a nutshell, xvf tells tar to verbosely display files as they're extracted. In this circumstance this is very useful!

You'll see a stream of filenames fill up your window, followed by a message similar to the following if you're tar file was corrupted.

[…]tar: End of archive volume 1 reached
[FILENAME].tar: Unexpected EOF on archive file

While you some of your files may have been extracted, clearly in this case you've received a poorly formed tar file. If possible, you should attempt to download it again from where you got it, or if you made it yourself try to find a backup.

Author bio and support


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.