Thursday, July 04, 2024

Unix Compress Tips (gz xz etc)

Unix Compress Tips (gz xz etc)

Another incomplete jumpstart tutorial or tips for unix compression.

There are a few types of unix compress format eg. gz, bz2, what are the differences? Z is very old unix compress, probable no one is using it now. The gz and bz2 (bzip2) is quite common for compressing text base file, eg. source code. The gz and bz2 format existed and commonly use for a long time (80s, 90s to...).

The xz is newer, it has a better compression ratio, but it also takes more resources (cpu and ram), normally used to compress large binary files. The Zip is very common in Windows systems.

The is how to compress 2 files, dummy and hello.txt:

## compress found in debian ncompress package
## '-c' to create archive, '-O' to output to stdout
## '-cO' same with '-c --to-stdout'
## '-cO' same with '-cf -'
$ tar -cO dummy hello.txt | compress -c > hello.tar.Z
⇒ hello.tar.Z

## gz, -z for gz
$ tar -czf hello.tar.gz dummy hello.txt

## bzip2, -j (capital J)
$ tar -cjf hello.tar.bz2 dummy hello.txt
⇒ hello.tar.bz2 in gzip2 format

## xz, -J
$ tar -cJf hello.tar.xz dummy hello.txt
⇒ hello.tar.xz in xz format

## zip
$ zip -r hello.zip dummy hello.txt

updating: dummy (stored 0%)
updating: hello.txt (deflated 49%)

Hope you enjoy these quick tips.

No comments: