How to Extract tar.xz Files in Linux

When you download source code, Linux packages, or backup archives, you may find files that end in .tar.xz or .txz. These are tar archives compressed with xz, and you can extract them with one command:
tar -xf archive.tar.xzThe tar command creates and extracts tar archives. It can also read common compression formats, including gzip, bzip2, and xz. By convention, a tar archive compressed with xz ends with either .tar.xz or .txz.
This guide explains how to extract .tar.xz and .txz files, list archive contents before extracting, unpack files to another directory, and fix common extraction errors.
Quick Reference
For a printable quick reference, see the tar cheatsheet .
| Task | Command |
|---|---|
| Extract tar.xz | tar -xf archive.tar.xz |
| Extract .txz | tar -xf archive.txz |
| Extract with verbose output | tar -xvf archive.tar.xz |
| Extract to another directory | tar -xf archive.tar.xz -C /path/to/dir |
| List contents | tar -tf archive.tar.xz |
| List contents with details | tar -tvf archive.tar.xz |
| Extract specific files | tar -xf archive.tar.xz file1 file2 |
| Extract matching files | tar -xf archive.tar.xz --wildcards '*.png' |
| Extract from stdin | wget -O - URL | tar -xJ |
| Preserve permissions | tar -xpf archive.tar.xz |
| Skip existing files | tar -xf archive.tar.xz --skip-old-files |
Extracting tar.xz Files
The tar utility is pre-installed on most Linux distributions and macOS. For a regular .tar.xz file stored on disk, use tar -xf followed by the archive name:
tar -xf archive.tar.xzThe -x option tells tar to extract files, and -f tells it to read from the archive file that follows. Modern tar versions auto-detect the xz compression, so you do not need to add the -J option when extracting a local file.
The same command also works for the shorter .txz extension:
tar -xf archive.txzThe archive contents are extracted into the current working directory
. If the archive contains a top-level directory, tar recreates that directory and places the files inside it.
To print each file name as it is extracted, add the -v option:
tar -xvf archive.tar.xzVerbose output is useful when you want to confirm that tar is working or when you need to see the paths stored inside the archive.
The tar -xf pattern also works with other tar compression formats, such as .tar.gz
and .tar.bz2
, when your tar version supports automatic compression detection.
Extracting to Another Directory
Use the --directory (-C) option to extract the archive into a specific directory. The target directory must already exist.
For example, to extract archive.tar.xz into /home/linuxize/files, run:
tar -xf archive.tar.xz -C /home/linuxize/filesIf the directory does not exist, create it first:
mkdir -p /home/linuxize/files
tar -xf archive.tar.xz -C /home/linuxize/filesThis keeps the extracted files away from your current directory and makes cleanup easier if the archive contains many paths.
Listing tar.xz File Contents
Before extracting an archive from an untrusted or unfamiliar source, list its contents. This shows where files will be written.
To list the contents of a .tar.xz file, use the --list (-t) option:
tar -tf archive.tar.xzThe output shows the paths stored in the archive:
file1
file2
file3For a detailed listing with permissions, owners, sizes, and timestamps, add -v:
tar -tvf archive.tar.xzThe output will look similar to this:
-rw-r--r-- linuxize/users 0 2026-01-15 01:19 file1
-rw-r--r-- linuxize/users 0 2026-01-15 01:19 file2
-rw-r--r-- linuxize/users 0 2026-01-15 01:19 file3Use this list when you need the exact path for extracting one file or directory.
Extracting Specific Files from a tar.xz File
To extract specific files from a .tar.xz archive, place their archive paths after the archive name:
tar -xf archive.tar.xz file1 file2The file names must match the paths shown by tar -tf. If the archive stores files under a directory such as project/, include that directory in the path:
tar -xf archive.tar.xz project/file1 project/file2You can extract directories the same way:
tar -xf archive.tar.xz project/docsIf you try to extract a path that does not exist in the archive, tar prints an error like this:
tar -xf archive.tar.xz READMEtar: README: Not found in archive
tar: Exiting with failure status due to previous errorsThe message means the path you provided does not match the path stored in the archive. Run tar -tf archive.tar.xz and copy the exact path from the listing.
You can also extract files by wildcard pattern. Use the --wildcards option and quote the pattern so your shell does not expand it before tar sees it.
For example, to extract files whose names end in .png, run:
tar -xf archive.tar.xz --wildcards '*.png'Extracting tar.xz Files from stdin
When reading a .tar.xz archive from standard input, usually through a pipe, specify the xz decompression option. The -J option tells tar that the incoming stream is compressed with xz.
The following example downloads a Linux kernel archive with wget
and extracts it from the stream:
wget -c https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.12.68.tar.xz -O - | sudo tar -xJWhen extracting from stdin, there is no file extension for tar to inspect. If you leave out -J, tar may print this message:
tar: Archive is compressed. Use -J option
tar: Error is not recoverable: exiting nowAdd -J and run the command again.
To extract the stream into a specific directory, combine -J with -C:
wget -O - https://example.com/archive.tar.xz | tar -xJ -C /tmp/filesExtracting and Preserving Permissions
By default, tar preserves file modes when extracting. If you are restoring system files as root and want to preserve the original permissions more explicitly, use the -p option:
sudo tar -xpf archive.tar.xzThis keeps the permissions stored in the archive. Ownership handling depends on the user running the command and the metadata stored in the archive.
For archives from unknown sources, inspect the contents before extracting as root:
tar -tvf archive.tar.xzThis helps you spot unexpected paths or ownership before writing files to the system.
Handling Existing Files
When extracting, tar overwrites existing files by default. To keep existing files and skip archive files with the same path, use --skip-old-files:
tar -xf archive.tar.xz --skip-old-filesTo keep newer files on disk and overwrite only older files, use --keep-newer-files:
tar -xf archive.tar.xz --keep-newer-filesIf you want tar to fail instead of overwriting an existing file, use --keep-old-files:
tar -xf archive.tar.xz --keep-old-filesThis is useful when you are extracting into a directory that already contains important files.
Extracting tar.xz Files without the Command Line
Most Linux desktop file managers can extract .tar.xz files. Right-click the archive and choose the extract option from the context menu.
On Windows, tools such as 7-Zip
can open and extract .tar.xz files. A .tar.xz archive has two layers, so the tool may first decompress the .xz layer and then show the .tar archive inside it.
Troubleshooting
tar: Archive is compressed. Use -J option
This usually happens when you read a .tar.xz archive from stdin without telling tar which decompressor to use. Add -J:
cat archive.tar.xz | tar -xJFor local files, prefer tar -xf archive.tar.xz, because tar can usually detect the compression from the file itself.
tar: README: Not found in archive
The file path you typed does not match the path inside the archive. List the archive contents first:
tar -tf archive.tar.xzThen copy the exact file path from the output and use it in the extract command.
tar: archive.tar.xz: Cannot open: No such file or directory
The archive name or path is wrong, or you are running the command from a different directory. Check the file name:
lsIf the archive is in another directory, provide the full path:
tar -xf /path/to/archive.tar.xzxz support is missing
Most current Linux systems include xz support, but minimal installations may not. On Ubuntu, Debian, and derivatives, install the xz tools with:
sudo apt install xz-utilsOn Fedora, RHEL, and derivatives, install the xz package with:
sudo dnf install xzAfter installing the package, run the tar -xf archive.tar.xz command again.
You have an .xz file, not a .tar.xz file
A .tar.xz file is a tar archive compressed with xz. A plain .xz file is usually one compressed file, not an archive. To decompress a plain .xz file, use:
unxz file.xzIf you need to keep the original .xz file, use:
xz -dk file.xzFAQ
What is the difference between tar.xz and tar.gz?
Both are tar archives compressed with different algorithms. xz uses LZMA2 and usually produces smaller files, but compression is slower. gzip is faster, but the resulting archive is often larger. For local files, the extraction command is the same: tar -xf archive-name.
Do I need to install xz to extract tar.xz files?
On most Linux distributions, xz is pre-installed. If tar reports that xz support is missing, install it with sudo apt install xz-utils on Debian/Ubuntu or sudo dnf install xz on Fedora/RHEL.
What does the -J flag do?
The -J flag tells tar to use xz compression or decompression. You usually need it when reading from stdin or when creating a .tar.xz archive with tar -cJf. When extracting a file from disk, tar -xf archive.tar.xz is normally enough.
Is tar.xz the same as xz?
No. A .tar.xz file is a tar archive compressed with xz, so it can contain many files and directories. A .xz file is usually a single compressed file. Use tar -xf archive.tar.xz for .tar.xz files and unxz file.xz for plain .xz files.
Can I extract a tar.xz file on macOS?
Yes. The tar command on macOS supports xz extraction. Use the same tar -xf archive.tar.xz command.
How do I create a tar.xz archive?
Use tar -cJf archive.tar.xz file1 file2 dir1. The -c flag creates the archive, and -J compresses it with xz. For more details, see our guide on creating tar archives
.
Conclusion
The tar -xf archive.tar.xz command is the simplest way to extract .tar.xz and .txz archives from disk. For broader archive workflows, see the full tar command guide
and the related guides for tar.gz
and tar.bz2
files.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page