4

I tried to run:

tar -zxvf name.tar.xz

but all I got was:

tar: Child returned status 2
tar: Error is not recoverable: exiting now
  • What do you call a normal install? A tar.xz is just a compressed archive of files. – Majenko Dec 13 '15 at 14:25
  • I tried tar -zxvf name.tar.xz – IlikeBananas Dec 13 '15 at 14:26
  • Try replacing the z with J – Majenko Dec 13 '15 at 14:27
  • 'gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now ' – IlikeBananas Dec 13 '15 at 14:31
  • 3
    What happens with tar --xz -xvf name.tar.xz? – muru Dec 13 '15 at 16:06
14

The z flag of GNU tar (which is the version of tar shipped with Ubuntu) is used to speciy that the archive being processed is compressed using gzip, which is usually indicated by the .tar.gz (or, more rarely, .tgz) extension. In GNU tar, it is an error to use the z flag if the archive is not compressed with gzip, as you experience now.

Archives using the .tar.xz extension are compressed with xz, and the corresponding flag in GNU tar is J. Hence, replacing z with J in your command should solve your problem. In addition, you may get a "command not found" error if the xz tools are not installed on your system, which can be remedied by installing the xz-utils package.

Alternatively, you can simply omit the filetype-related flag altogether, and simply use -xvf; in that case tar will attempt to autodetect the compression format by analyzing the file. (You can probably also dispense with the v flag; it just prints a list of the extracted files, which is not usually useful.)

  • Alternatively, use the a flag to automatically determine the appropriate (de-)compressor from the archive file name. – David Foerster Dec 13 '15 at 23:38
  • 1
    @DavidFoerster No, the a flag is only used when creating archives. When extracting, it is sufficient to just not use any filetype-related flag at all. – fkraiem Dec 13 '15 at 23:58
  • Cool! I didn't know that, but I just tried it. – David Foerster Dec 14 '15 at 10:58
3

.xz is "A compression format using LZMA2 to yield very high compression ratios" and should be extracted with ar (ar is installed by default as part of GNU utils).

The GNU ar program creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files (called members of the archive).

There are more tools (like tar) but whatever other tool you use: make sure that that tool supports this ->

The original files' contents, mode (permissions), timestamp, owner, and group are preserved in the archive, and can be restored on extraction.

0

I had a 'tar.xz', so I used unxz myfile.tar.xz to uncompress the file, so I got the archive file myfile.tar. Then using the regular tar command on an archive file, I could extract the contents tar xvf myfile.tar.

-1

You can use the command below to untar .tar.xz files.

Syntax:

tar -xJvf File_Name.tar.xz

Example:

tar -xJvf etc.tar.xz    
  • 3
    This is an exact duplicate of the most upvoted answer but with less information. – pLumo Oct 14 '19 at 14:25
  • 1
    @pLumo I’d keep this answer as it provides a TL;DR, copy-pasteable solution. I couldn’t find any answer on this page to which this would be an “exact duplicate”. – Melebius Oct 15 '19 at 7:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.