3

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
  • 365

5 Answers5

3

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
  • 498,455
3

You could use CMD/Bat to auto extract all .xz using 7z.. Simply Create a new text document, Copy code below into document.. Save document as something like.. ExtractXZ.bat (The .bat is Vital) And dont forget to select.. Save as type.. All Files.. before hitting Save.

Screenshot Example: https://prnt.sc/hteWD4M37MVL

This would be a customizable portable file for extracting archives.. Just double click it and let it extract every .xz it finds.

You can change code to make it search in a different location or for different archive types or where it extracts them etc

Code for Using Portable 7z in 7-Zip folder in same Dir as bat file..

@echo off
for /r "%~dp0" %%A in (*.xz) do (
     echo  Extracting.. %%A
     "%~dp07-Zip\7z.exe" x "%%A" -aoa -o"%~dp0ExtractMeHere" -r -y >nul
     )
pause

Code for Using Installed 7z..

@echo off
for /r "%~dp0" %%A in (*.xz) do (
     echo  Extracting.. %%A
     "7z x "%%A" -aoa -o"%~dp0ExtractMeHere" -r -y >nul
     )
pause

"%~dp0" means it will search in the same dir as itself, Change to suit your needs.

*.xz is what to search for.. All .xz files found will be processed.

"%~dp0..7z.exe" x.. is the extract cmd, %%A gets Extracted to a Folder called ExtractMeHere in bat dir.

If you wish to see 7z processing the files.. remove.. >nul off the end, i just think it looks nicer :)

Venom
  • 71
2

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.

user219095
  • 65,551
1

I recently was looking at this while writing a powershell script to extract cygwin1.dll which comes in tar.xz files. I was trying to figure out why my script worked on one machine and not another. Yes you can use 7zip but that does not come with Windows. What I figured out was that older versions of Windows you must 7zip use because they did not backport the latest version of tar. There may be some KBA or something you could install, but I just resorted to 7zip for now.

Some versions of windows (21H2) have a version that can't extract xz files.

PS> tar.exe --version
bsdtar 3.5.2 - libarchive 3.5.2 zlib/1.2.5.f-ipp bz2lib/1.0.6 

Other versions of windows (22h2 and 23h2) have a version seems to be able to extract tar.xz files.

PS> tar.exe --version
bsdtar 3.6.2 - libarchive 3.6.2 zlib/1.2.5.f-ipp liblzma/5.2.5 bz2lib/1.0.8 libzstd/1.5.4`

You also should check to your tar.exe filepath, because you could be using cygwin or some other version of tar installed in your path.

PS> Get-Command tar.exe

CommandType Name Version Source


Application tar.exe 10.0.22... C:\Windows\system32\tar.exe

The comments stating windows tar does not do xz files is partially incorrect.

jc3
  • 11
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
  • 141