1

I have a bunch of tar.xz files I need to extract. I tried using the following command, but get an error.

tar -xJf "S:This_Is\the path\to_my_file.tar.xz"

tar: Error opening archive: Can't initialize filter; unable to run program "xz -d -qq"

I have tried both -xJf and -xf and get the same result. I am able to use 7-zip to open the files, but for this I have to manually unzip each file from .xz first and then untar, and this is a bit of a pain. I have previously been able to use a .bat file to extract lots of tar.gz files and would like to do the same for the tar.xz files. Is there a way to make this work?

David K
  • 321
  • 2
  • 4
  • 15
  • If I can make a suggestion outside of the answers below. I use WSL and POSIX commands work right out of the box. (I myself still prefer WSL1).. Best of both worlds.. no more running ported applications. No more missing basic utilities. Best part is you can mix windows and unix utilities all from the same command line. – Señor CMasMas Aug 04 '22 at 00:25

3 Answers3

2

xz is the most modern LZMA2 compression option, which apparently the Windows tar program does not support.

You should use another program that does support it, such as 7-Zip.

If the latest 7-Zip does not support xz, try its fork 7-Zip-zstd which supports more compression methods.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • My 7-zip does support `xz` files, as I mentioned in my question, but I only know how to use it to manually extract files in multiple steps. Is there a way to use 7-zip to run on a batch of files, or to extract directly from `tar.xz` rather than needing to do it in two steps? – David K Aug 03 '22 at 18:50
  • 7-Zip needs two steps, which can be done using a batch script. Try also [XZ Utils](https://tukaani.org/xz/). I don't have a sample file to test, but I've seen these utils recommended for `xz` archives. – harrymc Aug 03 '22 at 19:07
  • Using `7z` in a batch script looks like the best option for me - I just need to make sure the command is on my path. It still takes two steps, but at least I can script it up. – David K Aug 04 '22 at 13:19
0

tar doesn't do compression itself. Instead, it relies on external compressors, like gzip, bzip2 and also xz. Without these separate commands being available, you will not be able to use the corresponding compression type.

So all you need to do is put the xz binary in %PATH%, where tar can find it, and you're good to go.

You might be able to get xz using the same way you got tar.

Daniel B
  • 60,360
  • 9
  • 122
  • 163
  • 1
    *GNU* tar uses separate compressors as you say, but the `tar[.exe]` supplied by Windows 10 (no 'getting' needed) is bsdtar/libarchive with gzip (deflate) builtin -- only. – dave_thompson_085 Aug 04 '22 at 02:30
  • While _bsdtar_ might have some compression types built-in, it will still fall back to external tools, as evident from OP’s error message. – Daniel B Aug 04 '22 at 18:50
0

As stated in other answers Windows' tar (bsdtar) does not come with LZMA (.xz) compression tools. However they are misleading into suggesting that you cannot use bsdtar with .xz.

All you need to do is install XZ Utils which can be found here under "Pre-built binaries".

Shidouuu
  • 111
  • 3