0

I'm taking a dd of a drive and trying to share it with a friend. It's rather big after dd (~8gb). When I tar -czvf my-image.img I can get it down to ~1.5gb. However, if I try to test unzip it, I see that the shasum hash of the unzipped file is different from the file I had originally before zip. Is there a way I can "lossless" zip a file?

4
  • 4
    You're already assuming that tar/gzip is normally lossy. No, that's not normal. Commented Aug 6, 2021 at 22:42
  • I don't understand. Are you saying there's no way to tar/gzip a file and expect it to be identical on unzip?
    – gh0st
    Commented Aug 6, 2021 at 22:47
  • 3
    We're saying what you described should compress losslessly in the first place. You're assuming it's lossy where by design it is not. In fact I haven't even heard of a way to make tar+gzip lossy on demand. Please edit and provide the exact commands you used to read, compress, copy, uncompress, compute hashes etc.; all relevant commands. The best we have for now is tar -czvf my-image.img and it's not even a complete command that would work. Commented Aug 6, 2021 at 23:37
  • Compressing a data file is not at all the same thing as compressing a digital audio or video file. This is what the others are trying to say, because it seems you're making the error of conflating the two very different things. Commented Aug 7, 2021 at 3:44

1 Answer 1

0

As others have stated zip (and gzip & which is what you are actually using) are lossless. If the 2 files are not identical its because of corruption that should not be occurring or, more likely you gave implemented the command wrong.

The way you are attempting this is sub-optimal, the command you are looking for should be

  tar -czvf my-image.tar.gz my-image.img

And to decompress

  tar -zxf my-image.tar.gz

Of-course, the command you are using is designed to work to package and compress multiple files. As you only have a single file you dont need to use tar at all, you should just use gzip -

 gzip my-image.img

and to decompress

gunzip my-image.img.gz

You must log in to answer this question.

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