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

前端 未结 7 797
难免孤独
难免孤独 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 15:56

    Well, you can do that if you previously creates an index for each file ...

    I've developed a command line tool which creates indexes for gzip files which allow for very quick random access inside them, and it does this interleaved with actions (extract, tail, continuous tail, etc): https://github.com/circulosmeos/gztool

    But you can do a tail (-t), and the index will be automatically created: if you're gonna do the same in the future it'll be much quicker, and anyway the first time it will take the same time as a gunzip | tail:

    $ gztool -t my_file.gz
    

提交回复
热议问题