ZSTD compression level with tar

I've been using zstd more and more for general compression. Using it with tar is pretty straight forward:

tar -I zstd -cvpf /tmp/etc.tar.zst /etc

This does not allow you to set the compression ratio however. After some digging I found an environment variable that controls the default compression level. If you run tar like this you can change the default compression level.

ZSTD_CLEVEL=19 tar -I zstd -cvpf /tmp/etc.tar.zst /etc

GZip has a similar variable, but it will allow any command line variable (not just compression ratio).

GZIP=-9 tar -cvzpf /tmp/etc.tar.gz /etc

Update: You can also use ZSTD_NBTHREADS to use more CPU cores.

Leave A Reply - 3 Replies
Replies
Tudor Georgescu 2020-12-11 08:47pm - tgeorgescu@... - Logged IP: 82.75.182.62

It has to be:

ZSTD_CLEVEL=19 tar -I zstd -cvpf /tmp/etc.tar.gz /etc

Otherwise, it will be saved to the file -I.

Rishabh Arya 2021-04-15 04:24am - No Email - Logged IP: 117.97.156.230

We can specify the compression level within the command itself:

tar -I "zstd -19" -cvpf /tmp/etc.tar.zst /etc

A Davis 2024-10-28 09:19am - No Email - Logged IP: 107.190.3.153

The use of -p here is superfluous -- it only applies to extraction of the archive.

All content licensed under the Creative Commons License