3

I've received a Tar/GZipped file that was created on an embedded Linux device.

The file can be extracted perfectly fine on a Linux desktop if I run something like tar zxf myFile.tgz. The file extracts to something like

dir1/
  file1
  file2
dir2/
  file1
  file2
  subdir1/
    file1

...but I suspect the specific file content and layout are irrelevant.

When I try to extract this same file in Windows (using either 7-Zip or WinZip), I get:

  myFile/
    <extensionless file with temp-looking name e.g. "logs_xqUt09">

It's probably relevant that that top-level directory happens to be named "myFile" when the .tgz I received is itself named myFile.tgz...but I don't know with certainty that it's anything more than coincidental.

I browsed SuperUser a bit, and found a few related issues, one of which suggested that 7-Zip handles .tgz files better than WinZip, but apparently not in this situation.

Does anyone know what gives? Why would a .tgz be fully extractable under Linux but not Windows? What workarounds might there be?

If I rename that extensionless file to a .tar file, then that .tar file is extractable with 7-Zip and/or WinZip.

I'd still like to understand what's going on, and if there's a workaround that doesn't involve that manual file renaming, because ideally the original .tgz file delivered by the embedded device should be extractable under Linux and Windows.

1
  • There is WSL and Starting with version 1803, Windows 10 is adding native support for tar
    – LotPings
    Apr 3, 2019 at 0:20

3 Answers 3

5

tgz (tar.gz) is a two-level-archive. first a stream of files is saved as tar. second the tar file is compressed with gzip. if you extract a gzip file you will always get a single file - extensionless file with temp-looking name in case of 7-zip. this file can "unpacked" with tar, or with 7-zip again.

besides tar stream contains metadata like file permissions, group id + user id, xattrs or selinux context (and maybe symbolic links) which get lost on windows file system, unpacking linux files may fail or cause trouble because of the ascii charset in file names (all chars except / allowed in linux). usually it makes no sense to extract tar archive to windows disk

1

Why?

Because Microsoft hasn't/hadn't built that in yet.

File types are only supported by an OS when the necessary instructions are added to that OS to tell it how to handle the files.

.tag.gz has a long history of use in *nix systems, but .zip and other packages are much more popular in Windows and so there hasn't been any real demand to support those package types in Windows.

Any further than that we cannot answer because we are not the people who write Windows.

1

A .tgz fully extractable on a Linux system, because tar was built by AT&T Bell Laboratories specifically for Unix and Unix-like operating systems. And gzip is just a compression algorithm that was developed years after tar had been developed.

The same rationale goes for all other file extensions that are supported on one OS but not another. For example, you can't use a .dmg file on Windows, and you can't use a .msi on macOS.

Most people choose the tar.gz option on Linux/Unix because tar stores Unix file attributes and permissions, and consolidates all of the files to be archived. Then gzip is used to compress it.

The zip option stores MSDOS file attributes, then compresses each file individually and then consolidates each individual file into one file.

Depending on your situation, instead of taring and gzipping the file on the embedded device, you could use the zip command instead.

You must log in to answer this question.

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