24 October 2021

In Unix/Linux there are special commands used to manage compressed files, the most common are:

All these commands could be used also for non compressed file.

Note: all example below could be execute in a container:

docker run -it  ubuntu /bin/bash
apt update && apt install -y less

zcat

Like cat show an entire content of a compressed/uncompressed file.

$ cd /tmp && echo -e "test1\ntest2\ntest3" > test.txt

$ gzip --keep test.txt

$ zcat test.txt.gz
test1
test2
test3

$ zcat test.txt
test1
test2
test3

zgrep

Like grep search a string in a compressed/uncompressed file.

$ cd /tmp && echo -e "test1\ntest2\ntest3" > test.txt

$ gzip --keep test.txt

$ zgrep test2 test.txt.gz
test2

$ zgrep test3 test.txt
test3

zmore

Like more show a content of a file one page at a time.

$ cd /tmp && echo -e "test1\ntest2\ntest3" > test.txt

$ gzip --keep test.txt

$ zmore test.txt.gz

$ zmore test.txt

zless

Like less show a content of a file one page at a time but is it possibile search a string or scroll up and down from a file.

$ cd /tmp && echo -e "test1\ntest2\ntest3" > test.txt

$ gzip --keep test.txt

$ zless test.txt.gz

$ zless test.txt

zdiff

Like diff show differences between two compressed/uncompressed files.

$ cd /tmp && echo -e "test1\ntest2\ntest3" > file1.txt && echo -e "test1\ntest--2\ntest4" > file2.txt

$ gzip --keep file1.txt && gzip --keep file2.txt

$ zdiff file1.txt.gz file2.txt.gz
2,3c2,3
< test2
< test3
---
> test--2
> test4

$ zdiff file1.txt.gz file2.txt
2,3c2,3
< test2
< test3
---
> test--2
> test4

References