tar cv /path/to/directory | gzip --best > file.tar.gz
This is Matrix Mole's second solution, but slightly shortened:
When calling tar, option f
states that the output is a file. Setting it to -
(stdout) makes tar write its output to stdout which is the default behavior without both f
and -
.
And as stated by the gzip
man page, if no files are specified gzip will compress from standard input. There is no need for -
in the gzip
call.
Option --best
(equivalent to -9
) sets the highest compression level.
3FYI, for .bz2 format, use: BZIP2=-9 tar cvjf file.tar.bz2 /path/to/directory – Tomofumi – 2017-03-02T02:59:46.520
3The environment variable seems to now be
GZIP_OPT
, the usage should be the same. – Seer – 2017-12-05T11:59:30.8633From the man page on Ubuntu 16.04 for gzip: "On Vax/VMS, the name of the environment variable is GZIP_OPT, to avoid a conflict with the symbol set for invocation of the program." For sh, csh, and MSDOS it should still just be GZIP – Ponyboy47 – 2018-06-02T16:13:19.823
This is what I get when I try to set
GZIP
environment variable to-9
: gzip: warning: GZIP environment variable is deprecated; use an alias or script – patryk.beza – 2019-10-31T10:43:16.08015pigz is "parallel gzip" which uses all your cores for gzip compression. You can watch
top
and see it using anywhere between 200%-400$ CPU. – Felipe Alvarez – 2013-12-09T02:01:03.163