If you need to check the contents of a compressed text file on Linux, you don't have to uncompress it first. Instead, you can use a zcat or bzcat command to extract and display file contents while leaving the file intact. The "cat" in each command name tells you that the command's purpose is to display content. The "z" tells you that it works with compressed files.\nWhich of the two commands to use depends on the type of compressed file you are examining. If the file was compressed with gzip or zip, you would use the zcat command. If the file was compressed with bzip2, you would use the bzcat command. On some systems, zcat might be called gzcat.\nYou can identify the command used to compress a file by the compressed file's extension.\n\n.gz or .tgz = gzipped files, use zcat (or gzcat)\n.zip = zipped files, use zcat (or gzcat)\n.bz2 = bzipped files, use bzcat\n\nIn the example below, the top 20 lines of H. G. Wells' "The War of the Worlds" is displayed from a file compressed with bzip2.\n$ bzcat The_War.bz2 | head -20\nNo one would have believed in the last years of the nineteenth century\nthat this world was being watched keenly and closely by intelligences\ngreater than man\u2019s and yet as mortal as his own; that as men busied\nthemselves about their various concerns they were scrutinised and\nstudied, perhaps almost as narrowly as a man with a microscope might\nscrutinise the transient creatures that swarm and multiply in a drop of\nwater. With infinite complacency men went to and fro over this globe\nabout their little affairs, serene in their assurance of their empire\nover matter. It is possible that the infusoria under the microscope do\nthe same. No one gave a thought to the older worlds of space as sources\nof human danger, or thought of them only to dismiss the idea of life\nupon them as impossible or improbable. It is curious to recall some of\nthe mental habits of those departed days. At most terrestrial men\nfancied there might be other men upon Mars, perhaps inferior to\nthemselves and ready to welcome a missionary enterprise. Yet across the\ngulf of space, minds that are to our minds as ours are to those of the\nbeasts that perish, intellects vast and cool and unsympathetic,\nregarded this earth with envious eyes, and slowly and surely drew their\nplans against us. And early in the twentieth century came the great\ndisillusionment.\n\nTo display only a portion of the text, pass the command output to another command like the head command shown above or to a grep command that includes the text you are searching for. For example:\n$ bzcat The_War.bz2 | grep vastness\nHaggerston and Hoxton, and, indeed, through all the vastness of London\nthroughout the inanimate vastness of sidereal space. But that is a\n\nAfter the bzcat display, the file remains compressed.\n$ ls -l The_War.bz2\n-rw-r--r--. 1 shs shs 100677 May 23 15:40 The_War.bz2\n\nIf you want to uncompress the file instead of just checking its content, use bunzip2.\n$ bunzip2 The_War.bz2\n$ ls -l The*\n-rw-r--r--. 1 shs shs 345315 May 23 15:40 The_War\n\nTo compress the file again, use the bzip2 command.\n$ ls -l\n-rw-r--r--. 1 shs shs 100677 May 23 15:40 The_War.bz2\n\nThe zcat command works the same way, but with gzip and zip files.\n$ zcat The_War.gz | grep vastness\nHaggerston and Hoxton, and, indeed, through all the vastness of London\nthroughout the inanimate vastness of sidereal space. But that is a\n$ ls -l The_War.gz\n-rw-r--r--. 1 shs shs 132099 May 23 15:40 The_War.gz\n\nTo wrap up, the table below provides a list of the commands used to compress, uncompress and display the contents of compressed files without uncompressing them. Note that the zip command requires that you supply the name of the compressed file to be created and does not compress the file "in place" (i.e., leaving you with only that file) as the other two commands do.\n\n\n\nTo compress\nTo uncompress\nTo display without uncompressing\n\n\nbzip2\nbunzip2\nbzcat\n\n\ngzip\ngunzip\nzcat\n\n\nzip\nunzip\nzcat\n\n\n\nNote that the compression commands and formats used are different and compression rates will depend on file content as well as the commands used. The zcat and bzcat commands are surprisingly fast. The results of compressing the same file using the three commands are shown below.\n$ bzip2 The_War\n$ gzip The_War\n$ zip The_War.zip The_War\n$ ls -l\ntotal 364\n-rw-r--r--. 1 shs shs 100677 May 23 16:47 The_War.bz2\n-rw-r--r--. 1 shs shs 132099 May 23 15:40 The_War.gz\n-rw-r--r--. 1 shs shs 132245 May 23 16:11 The_War.zip\n\nThe bzcat and zcat commands provide an easy way to verify the contents of compressed text files without requiring that you uncompress and then recompress the files. Keep in mind that these commands only work with compressed text files. You'll see a lot of output, but likely nothing of value if you try to look at a compressed image or tar file.