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 |
| Decompress a plain .xz file | unxz file.xz |
| Decompress and keep the .xz file | xz -dk file.xz |
| Inspect a .xz file | xz -l file.xz |
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 Plain .xz Files
Not every file ending in .xz is a tar archive. A .tar.xz file bundles files and directories with tar and then compresses the bundle with xz. A plain .xz file is a single compressed file with no tar archive inside it, and tar cannot unpack it.
The file command reports the compression, but it does not tell you what is underneath:
file notes.txt.xznotes.txt.xz: XZ compressed data, checksum CRC64A .tar.xz archive produces the same line, so decompress the stream and pass it to file when you need to know what is inside:
xz -dc archive.xz | file -/dev/stdin: POSIX tar archiveWhen the output names a tar archive, extract it with tar -xf even if the file name lacks the .tar part. Anything else is a single compressed file, and the xz tools handle it.
The unxz command decompresses the file and replaces notes.txt.xz with notes.txt:
unxz notes.txt.xzunxz is the same program as xz running in decompression mode, so the --decompress (-d) option does the same thing:
xz -d notes.txt.xzBoth commands delete the .xz file once decompression succeeds. Add the --keep (-k) option when you want to keep the compressed copy:
xz -dk notes.txt.xzTo read the contents without writing anything to disk, use the --stdout (-c) option and pipe the output to a pager or another command:
xz -dc notes.txt.xz | lessLarge downloads are worth checking before you spend time on them. The --test (-t) option verifies the integrity of the compressed data and prints nothing when the file is intact:
xz -t notes.txt.xzThe --list (-l) option reports the compressed and uncompressed sizes, which tells you how much free space the decompressed file needs:
xz -l notes.txt.xzStrms Blocks Compressed Uncompressed Ratio Check Filename
1 1 84 B 18 B 4.667 CRC64 notes.txt.xzExtracting 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.104.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
When run as root, tar restores the stored permissions by default. As a regular user, tar subtracts your umask from the modes recorded in the archive, so the extracted files can end up more restrictive than the originals. Use the -p option to apply the permission bits exactly as stored:
sudo tar -xpf archive.tar.xzOwnership handling depends on the user running the command and the metadata stored in the archive. A regular user cannot assign extracted files to another owner.
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.
Installing Software from a tar.xz File
A .tar.xz extension describes how files are packaged, not how the software is installed. The archive may contain a precompiled program, source code, or a project-specific installer. Check the project’s download or installation instructions before you continue.
List the archive first so you can see whether it contains a top-level directory and look for files such as README or INSTALL:
tar -tf app.tar.xz | lessWhen every path begins with a directory such as app-1.2.3/, extract the archive as your regular user and change into that directory:
tar -xf app.tar.xz
cd app-1.2.3Replace app-1.2.3 with the directory name shown by tar -tf. If the archive contains a precompiled program, follow the project’s instructions for choosing an installation directory and adding its executable to your PATH. Archive layouts differ, so there is no safe generic /opt path or symbolic-link command.
If the files are stored at the archive root, create a working directory before extracting them:
mkdir app-files
tar -xf app.tar.xz -C app-files
cd app-filesSource archives require a compiler and build tools. Install them before following the build system used by the project.
On Ubuntu, Debian, and derivatives:
sudo apt install build-essentialOn Fedora, RHEL, and derivatives:
sudo dnf group install "Development Tools"Building Autotools Source
Use the Autotools commands when the extracted directory contains an executable configure script:
./configure --prefix="$HOME/.local"
make
make installThe prefix installs the program under your home directory and avoids sudo. If ./configure reports a missing dependency, install the matching development package and run the command again.
Building CMake Source
When the directory contains CMakeLists.txt, install CMake first. On Ubuntu, Debian, and derivatives, run:
sudo apt install cmakeOn Fedora, RHEL, and derivatives, run:
sudo dnf install cmakeUnless the project documents different options, configure, build, and install it with:
cmake -S . -B build -DCMAKE_INSTALL_PREFIX="$HOME/.local"
cmake --build build
cmake --install buildSoftware installed from source is not tracked by apt or dnf, so those package managers cannot upgrade or remove it. Some Autotools projects provide make uninstall from the original build directory, while other projects require manual removal or their own uninstall procedure. Prefer a distribution package or an upstream package repository when one is available.
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 filetar cannot unpack a single compressed file. Decompress it with unxz file.xz, or see Extracting Plain .xz Files
for the full set of options.
FAQ
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 hold many files and directories. A plain .xz file is a single compressed file. See Extracting Plain .xz Files
for the commands that handle it.
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