On Linux servers, logs are often compressed in gzip format to save disk space because ‘/var/log’ filesystem mounted separately with small size, it would be 5-8GB.
You can examine the contents of compressed files on Linux systems without uncompressing/extracting the files using 'z*'
commands. These commands allow you to read gzip compressed text files using zless, zcat, bzcat, and zmore commands.
This post explains how to read the contents of compressed files and directories in Linux without extracting them, by leaving the file intact.
Normally, the user would decompress the file without the '-C'
parameter, which would replace the contents to the current log file, if it was compressed with the full path. Moreover you will lose current logs and because of this syslog will stop writing a live log to the file unless restarted. Therefore, to avoid this situation, we recommend reading uncompressed log files, but this is not only the reason for this, but also other facts should be considered.
You can use any of the below Z commands based on your requirement to achieve this task.
Command | Usage | Example |
---|---|---|
zcat/bzcat | cat to view the compressed files with .gz & .bz2 | zcat [Path/to/test.gz] / bzcat [Path/to/test.bz2] |
zless/bzless | less to view the compressed files in pages with .gz & .bz2 | zless [Path/to/test.gz] / bzless [Path/to/test.bz2] |
zmore/bzmore | more to view the compressed files in pages with .gz & .bz2 | zmore [Path/to/test.gz] / bzmore [Path/to/test.bz2] |
zgrep | grep to search matching string inside the compressed file | zgrep -i [String] [Path/to/test.gz] |
zdiff | diff to see the difference between two compressed files | zdiff [Path/to/test1.gz] [Path/to/test2.gz] |
To view the contents of a ZIP file without extracting, simply use zcat, zmore or zless command followed by the filename.
zcat FossTechi_Test.zip or zmore FossTechi_Test.zip or zless FossTechi_Test.zip
Same as less and more, you can use any of the below commands to view the contents of a gzip file without decompressing it in Linux.
zcat FossTechi.gz or zmore FossTechi.gz or zless FossTechi.gz
You can use any of the below commands to view the contents of a bzip2/bz2 file without extracting it in Linux.
bzcat FossTechi_Test.bz2 or bzmore FossTechi_Test.bz2 or bzless FossTechi_Test.bz2
grep is a very powerful command in Linux and zgrep allows you to search given keywords inside gzipped compressed files without extracting them.
zgrep -i keyword_search FossTechi_Test.gz
Similarly, you can use zdiff command to see the difference between gzip compressed files.
zdiff FossTechi_1.gz FossTechi_2.gz
In this short article, we have learned how to read compressed files without extracting them in Linux using zcat, zless, zmore, bzcat, bzless, bzmore, zgrep, and zdiff commands.
Cron is a command-line job scheduler available on Linux operating systems that allows users to…
In computing, there are two types of IP addresses, IPv4 and IPv6. By default, IPv6…
A tarball is commonly known as a TAR file, short for tape archive, which is…
A tar archive is a file that stores a collection of directories and files, also…
On Linux, you can quickly find out how LUNs are mapped to the underlying OS…
Keeping your Ubuntu system up-to-date is critical to ensuring a system's stability and security. This…
This website uses cookies.