'Tar ignores compression level, what to do? [closed]

Im using the following command(s):

GZIP=-9 tar -cf test9 directory
GZIP=-5 tar -cf test5 directory
GZIP=-2 tar -cf test2 directory

all test* result is the same, looks like compression level was ignored. How to get it into account?



Solution 1:[1]

You need to use the 'z' option to enable gzip compression, which then gave me the warning "gzip: warning: GZIP environment variable is deprecated; use an alias or script" with GZIP environment variable set.

I would use this syntax:

tar cf - directory | gzip -9 > test9.tar.gz

and just learned that you can also do:

tar cf test9 -I 'gzip -9' directory
``

Solution 2:[2]

TAR is file format that alignes content of files in a single chunk to increase dictionary and, as a result, decrease result archive size. You have to add -z option to compress resulting archive with gzip.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 stck