25

I use

tar -cJvf resultfile.tar.xz files_to_compress

to create tar.xz and

tar -xzvf resultfile.tar.xz

to extract the archive in current directory. How to use multi threading in both cases? I don't want to install any utilities.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
ewr3243
  • 357
  • 1
  • 3
  • 7

3 Answers3

34
tar -c -I 'xz -9 -T0' -f archive.tar.xz [list of files and folders]

This compresses a list of files and directories into an .tar.xz archive. It does so by specifying the arguments to be passed to the xz subprocess, which compresses the tar archive.

This is done using the -I argument to tar, which tells tar what program to use to compress the tar archive, and what arguments to pass to it. The -9 tells xz to use maximum compression. The -T0 tells xz to use as many threads as you have CPUs.

Alexander Batischev
  • 2,363
  • 11
  • 19
Artem S. Tashkinov
  • 26,392
  • 4
  • 33
  • 64
28

You can use XZ_DEFAULTS or XZ_OPT environment variables:

XZ_DEFAULTS is recommended to be used as a system wide configuration, typically set in a shell initialization script.

XZ_OPT is for passing options to xz when run by a script or tool, e.g. GNU tar. See man xz.

Example: using multiple threads (-T0) and max compression level (-9):

XZ_OPT='-T0 -9' tar -cJf resultfile.tar.xz files_to_compress

Reference with a recent GNU tar on bash or derived shell, also see the xz man page

Joel Purra
  • 133
  • 1
  • 6
wlads
  • 391
  • 3
  • 3
4

For older tars, this works:

tar -cf -  list of files and folders| xz -9 -T0 >| archive.tar.T.xz
AdminBee
  • 21,637
  • 21
  • 47
  • 71