Wednesday, February 23, 2011

Linux commands for gzip and bzip2

These examples are for compressing/decompressing, and preserving the original file.

Gzip-ing and gunzip-ing -
cat abc.txt | gzip > abc.gz
gzip -cd zbc.gz > abc.txt (-d decompress, -c send to console)

and similarly for bzip2 and bunzip2 -

cat abc.txt | bzip2 > abc.txt.bz2
gzip -cd abc.txt.bz2 > abc.txt

Some commands that operate directly on gzip-ped files -
zcat abc | less (abc can be a text file or a gzip-ped file)
zless def (the file need not have extension .gz)
zdiff abc.gz def
zgrep "pattern" abc.gz

and similarly for bzip2, we have bzcat, bzless, bzdiff and bzgrep.

No comments:

Post a Comment