Extract the tar.xz files from Linux

How do I unzip tar.xz files under Linux? Can you give me the command to unzip the linux-5.6.13.tar.xz file? How can I decompress (or extract) all files in the current directory?

The command tar and xz makes it possible to extract and decompress tar.xz files and .txz archives under Linux.

 

How do I unzip tar.xz files under Linux?

The syntax is as follows:

  1. Install xz with dnf install xz under CentOS/RHEL/Fedora Linux.
  2. Debian/Ubuntu Linux users will try to run apt install xz-utils
  3. Unpack tar.xz with the command tar -xf backup.tar.xz
  4. To decompress the .tar.xz filename, run: xz -d -v filename .tar.xz

Equipment

XZ is open source software for lossless data compressors, including LZMA and xz formats. These formats are popular with developers and open source projects because of the higher compression rates compared to alternative tools such as gzip and bzip2. The tar command works when xz is installed in the system. That’s why we have to install them.

Installation of Debin/Ubuntu Linux xz

Use the NA/apt-get command:
$ sudo apt install xz-utils
sample output :

Reading package lists… Ready
Build Dependency Tree
Read status information 4. Update
0, installed 0, newly installed 1, uninstalled 0 and not updated 5.
We need 82.5 kB of archives.
After this operation 0 V extra disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 xz-utils amd64 5.2.4-1 [82,5 kB]
Get 82,5 kB in 1 s (60,3 kB/s)
(Read database … 284817 files and directories currently installed)
Prepare to unpack … /xz-utils_5.2.4-1_amd64.deb …
Unpack the xz-tools (5.2.4-1) to (5.2.4-1)…
Adjusting the xz tools (5.2.4-1) ….
Triggering the treatment for man-db (2.9.1-1)…

Reading package lists… Done
Building dependency tree
Reading state information… Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 5 not upgraded.
Need to get 82.5 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 xz-utils amd64 5.2.4-1 [82.5 kB]
Fetched 82.5 kB in 1s (60.3 kB/s)
(Reading database … 284817 files and directories currently installed.)
Preparing to unpack …/xz-utils_5.2.4-1_amd64.deb …
Unpacking xz-utils (5.2.4-1) over (5.2.4-1) …
Setting up xz-utils (5.2.4-1) …
Processing triggers for man-db (2.9.1-1) …

CentOS/RHEL/Fedora Installation of Linux xz

Open the terminal application and execute the NA/dnf command as follows:
$ install sudo dnf xz
## On old CentOS/RHEL try yum ##
$ install sudo yum xz
From my CentOS 6.x box :

Downloaded plug-ins: fastestmirror
Installation process
Download speed of the mirror of the cached host file
* Base: centos.excemedia.net
* Add-ons: centos.excemedia.net
* Updates: centos.excemedia.net
Resolving dependencies
–> Performing transaction check
—> Package xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6 is set to
–> Finite dependency resolution

Dependencies are allowed

xz x86_64 4,999.9-0.5.beta.20091007git.el6 база 137 k

Краткий обзор перевода
==================================================================
Установка 1 Комплект(ы)

Total download size: 137 kSetting size: 477 kNormal [Y/N] : JPaket-Download:xz-4.999.9-0.5.beta.20091007git.el6.x86_64.rpm | 137 kB 00:00rpm_check_debug executeTransaction test successfulTransaction test executeTransaction installation: xz-4.999.9-0.5.beta.20091007git.el6.x86_64 1/1Test: xz-4.999.9-0.5.beta.20091007git.el6.x86_64 1/1

Installed:
xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6

All the way!

Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Resolving Dependencies
–> Running transaction check
—> Package xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
=================================================================================
Package Arch Version Repository Size
=================================================================================
Installing:
xz x86_64 4.999.9-0.5.beta.20091007git.el6 base 137 k
Transaction Summary
=================================================================================
Install 1 Package(s)
Total download size: 137 k
Installed size: 477 k
Is this ok [y/N]: y
Downloading Packages:
xz-4.999.9-0.5.beta.20091007git.el6.x86_64.rpm | 137 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : xz-4.999.9-0.5.beta.20091007git.el6.x86_64 1/1
Verifying : xz-4.999.9-0.5.beta.20091007git.el6.x86_64 1/1
Installed:
xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6
Complete!

Installing xz on OpenSUSE/SUSE Enterprise Linux

We can use the zypper command to install xz:
$ sudo zypper install xz
Extract the tar.xz files from Linux OpenSUSE xz for extraction.

Examples

Now we install xz. We can now directly use the tar command to extract a file named linux-5.6.13.tar as follows:
tar -xf linux-5.6.13.tar.xz
tar -xvf linux-5.6.13.tar.xz
tar -Jxvf linux-5.6.13.tar.xz
tar –xz -xf archive.txz
Extract the tar.xz files from Linux .

Extraction of specific files from tar.xzfile

We extract the specified filenames from backup.tar.xz using the following syntax:
$ tar -xf backup.tar.xz resume.pdf
$ tar -xf backup.tar.xz babys-3rd-cake-day.jpg sales.txt
Sometimes we don’t know the filenames in advance. So we list the contents of the archive in passing -t as follows:
$ tar -tvf backup.tar.xz
## Filter with grep/egrep command
$ tar -tvf backup.tar.xz | grep file1
$ tar -tvf backup.tar.xz | egrep ‘file.txt|data.doc|cake.jpg’
Output examples:

drwxrwxr root 0 2020-05-14 11:29 linux-5.6.13/.cocciconfig root 15844 2020-05-14 11:29 linux-5.6.13/.clang-root 59 2020-05-14 11:29 linux-5.6.13/.cocciconfig root 71 2020-05-14 11:29 linux-5.6.13/.cocciconfig root 71 2020-05-14 11:29 linux-5.6.13/.cocciconfig root 71 2020-05-14 11:29 linux-5.6.13/.get_maintainer.ignore-rw-rw-rw— root/root 62 2020-05-14 11:29 linux-5.6.13/.git attributes-rw-rw–root/root 1746 2020-05-14 11:29 linux-5.6.13/.gitignore-rw-rw-rw– root/root 15266 2020-05-14 11:29 linux-5.6.13/.mailmap-rw-rw-root 496 2020-05-14 11:29 linux-5.6.13/COPYING-rw-rw-root 99724 2020-05-14 11:29 linux-5.6.13/CREDITSdrwxrwxr-root 0 2020-05-14 11:29 linux-5.6.6/.13/Documentation/rw-rw-wool/root 13 2020-05-14 11:29 linux-5.6.13/Documentation/.gitignoredrwxrwxr root 0 2020-05-14 11:29 linux-5.6.13/Documentation/ABI/-rw-rw-wool/root 3821 2020-05-14 11:29 linux-5.6.13/Documentation/ABI/README

You want to extract all source files in Perl or Python? Try the following option:
tar –wildcards ‘*.py’ -xvf webroot.tar.xz
tar –wildcards ‘*.pl’ -xvf centos-7-sysadmin-scripts.txz

Understanding tar control options

  • -x : Unpack/save/unzip files from the archive.
  • -f archive.tar.xz : Use this archive file or the device archive to extract files.
  • -J OR –xz: Filter the archive with the xz command. So we install xz with the package manager.
  • -v : Oral. Show some progress.
  • -t : List of files stored in the .tar.xz/.xz archive
  • -wanted cards: By default, wildcards do not work because they are processed in your current shell. So use the –wildcards option to unzip the files. For example, get all the .webp images I would pass to –wildcards ‘*.webp’ tar option.

Conclusion

This short tutorial explains how to unpack and decompress common archive formats such as .tar.xz and .txz under the Linux operating system. Don’t forget that the tar command only works if you install the xz command via the packet manager. See the homepage of the xz-project and the documents here.

RECOMMENDATIONS

Published: Vivek gears

The author is the creator of nixCraft and an experienced system administrator, DevOps engineer and Linux/Unix shell script trainer. Receive the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly by email.how to extract tar.xz file in linux,how to extract img.xz file in linux,tar xz file decompress,how to extract tar.xz file in centos 7,how to read xz file linux,tar (child): xz: cannot exec: no such file or directory,extract xz file mac,tar.xz install

Share:

administrator