How can I tail a zipped file without reading its entire contents?

前端 未结 7 774
难免孤独
难免孤独 2020-12-15 15:21

I want to emulate the functionality of gzcat | tail -n.

This would be helpful for times when there are huge files (of a few GB\'s or so). Can I tail the last few li

7条回答
  •  温柔的废话
    2020-12-15 16:14

    If it's an option, then bzip2 might be a better compression algorithm to use for this purpose.

    Bzip2 uses a block compression scheme. As such, if you take a chunk of the end of your file which you are sure is large enough to contain all of the last chunk, then you can recover it with bzip2recover.

    The block size is selectable at the time the file is written. In fact that's what happens when you set -1 (or --fast) to -9 (or --best) as compression options, which correspond to block sizes of 100k to 900k. The default is 900k.

    The bzip2 command line tools don't give you a nice friendly way to do this with a pipeline, but then given bzip2 is not stream oriented, perhaps that's not surprising.

提交回复
热议问题