1

How to set compression level here?

nice -n 19 tar -czf $out $in 

1 Answer 1

4

nice won't do anything to the level of compression. It will only affect the scheduling of the process by the kernel. All commands below may be prefixed with nice to run them at a different "nice"-level, it will not influence the level of compression, only the time taken to perform the action (if the system is under heavy load).

If you're using GNU tar then the compression program may be set with either the -I or the --use-compress-program options:

$ tar -I "gzip --best" -c -f archive.tar.gz dir 

or

$ tar --use-compress-program="gzip --best" -c -f archive.tar.gz dir 

Note that the -z option should not be used if you set the compression program explicitly.

The GNU tar manual states that the program used must support an -d option for decompression (if you use these options for decompressing a compressed archive), which gzip does.

With BSD tar it's not possible to specify the level of compression in a similar way, as far as I have seen.

The other way to achieve this is obviously to create an un-compressed archive and then compress that in the way one wants:

$ tar -c -f archive.tar dir $ gzip --best archive.tar 

or

$ tar -c dir | gzip --best -o archive.tar.gz 

Yet another way is to set the GZIP environment variable to the flags that you'd like to pass to gzip:

$ export GZIP='--best' $ tar -c -z -f archive.tar.gz dir 

Except for the use of -I and --use-compress-program, the last few alternatives work with both GNU and BSD tar.

3
  • 1
    tar -c dir | gzip --best > archive.tar.gz Commented May 20, 2017 at 13:04
  • yes, but I need to use nice Commented May 20, 2017 at 13:18
  • 3
    @clarkk You may use nice. nice have no impact on the creation of the archive or on the compression, it just changes the scheduling of the tar/gzip process. My answer deals with setting the level of compression. Just prefix the commands with nice (as you did in your question) and it will work nicely. Commented May 20, 2017 at 13:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.