I had a rather big log file. So I thought I'd gzip it before transferring it to my pc. I did

gzip bla.log

which gave me a tiny


When I extract it using

gunzip bla.log.gz

I get back to my bla.log, but it's small and when I open it with vi it looks like this:


Why did this happen? Is there a way I can get my log file from this .gz archive?

And BTW I'm on a Linux x86_64 x86_64 x86_64 GNU/Linux

  • 1
    Had the process logging to the file finished with it before you compressed it? If file was still open in a process, the process can still write to the file even if you change the name. – James Waldby - jwpat7 Oct 25 '11 at 7:28
  • That's a good question. The process of zipping went really quick, way to quick for a >2GB text file, so I new something was fishy. In the end we restored the file from the backup. – Thomas Oct 31 '11 at 21:52

That's odd.

Exactly how small is it? How big was the original log file? What does file bla.log.gz say?

Normally gzip bla.log will write bla.log.gz and then, if that was successful, delete bla.log. gunzip blo.log.gz will write bla.log and then delete bla.log.gz.

If something goes wrong during the gzip command (say, it ran out of space, exceeded your quota, was killed by a signal, or the computer lost power), then you could easily end up with a partial or corrupted bla.log.gz file -- but then the original bla.log file should still be there.

And if you then run gunzip bla.log.gz, you should get a prompt like:

gzip: bla.log already exists; do you wish to overwrite (y or n)? 

It shouldn't have clobbered your original bla.log file unless (a) you told it to (by using gunzip -f or by anwering y to the above prompt), or (b) it successfully generated bla.log.gz.

To answer your question, if bla.log.gz consists of nothing more than a few zero bytes, you're not going to get anything useful out of it.

| improve this answer | |
  • I really don't know what happend. I asked the guy to restore the file from the backup and the second try worked the way you describe. BTW, the bla.log was about >2GB big – Thomas Oct 31 '11 at 21:51

Normally this should not happen. Try to read the gz file with a tool like gzless or something. If this is also screwed. Something went wrong while compression.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.