Pop quiz: what is wrong with this tar command?

Published on , 151 words, 1 minutes to read

It's stupider than you think

An image of A green haired anime woman with green eyes and very long hair angrily typing on a laptop, headphones, seattle, space needle, black hoodie, best quality, coffee shop
A green haired anime woman with green eyes and very long hair angrily typing on a laptop, headphones, seattle, space needle, black hoodie, best quality, coffee shop - Flux [dev]

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: