Pop quiz: what is wrong with this tar command?

Published on , 157 words, 1 minutes to read

It's stupider than you think

An image of A photo of the sunset taken from an airplane, it looks like night is breaking into the sky.
A photo of the sunset taken from an airplane, it looks like night is breaking into the sky. - Photo by Xe Iaso

Pop quiz: what is wrong with this tar command?

tar cf ../iosevka-iaso.tgz .
Aoi is wut
Aoi

That looks fine to me? You're creating a tarball in the parent directory with the contents of the current working directory. What's the problem?

$ tar xzf iosevka-iaso.tgz
gzip: not a compressed stream

The thing I messed up was not adding z to the tarball creation command. I needed to do:

tar czf ../iosevka-iaso.tgz .

This happens because GNU tar looks at file extensions to try to determine the user's intent. If you do tar xf foo.tgz or tar xf foo.tar.gz, it will invoke gzip to decompress the tarball for you. This is intended behavior, but that same logic doesn't run when you create a tarball.

I lost 15 minutes to this today and feel that I need to let y'all know so you can learn from my suffering.


Facts and circumstances may have changed since publication. Please contact me before jumping to conclusions if something seems wrong or unclear.

Tags: