How to look at the first 10 lines of the compressed file on Linux (file.gz)

How can I get and see few lines from a .gz compressed file without uncompressing it? Is it possible? Say I want first 10 lines of the compressed file on Linux . Please advice me.

Use the zcat command as follows:

zcat filename.gz | head -10
zcat /path/to/filename.tar.gz | head -10

The head will output the first 10 lines of files. See zcommands: Read gzip Compressed Text Files On a Fly on Linux and Unix


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki