Linux unxz Command: Decompress xz Files

unxz decompresses .xz files and works the same way as xz -d. By default, it replaces the compressed file with the original file.

What is the unxz command?

If you extract dump.sql.xz, dump.sql is created. To keep the compressed file, use -k. For .tar.xz files, even after decompression, the tar bundle remains, so tar -xJf is convenient when you want to extract individual files.

Basic syntax

unxz [options] file.xz [file.xz...]

Installed implementations and options may vary depending on the distribution. Check the description on your current system with man unxz.

Examples

Basic Decompression

Restores the .xz file to its original name.

unxz dump.sql.xz

Decompress while keeping the compressed file

Used when you need to archive or reuse the same data.

unxz -k dump.sql.xz

Check the content on standard output

Check the beginning part without creating the entire file on disk. Be careful with screen output if it is a binary file.

unxz -c notes.txt.xz | head

Extracting While Preserving the Original

unxz note.txt.xz usually removes the compressed file and restores note.txt. If you need to keep the compressed file, you can extract to standard output and save it to a separate path.

unxz -c note.txt.xz > restored.txt
ls -l restored.txt

If the first command succeeds, it ends quietly, and the second command will show the size and name of the restored file. The file size and contents vary depending on the input.

When redirecting, if the target file already exists, the shell may empty it first, so choose a new output name. If the restoration result is important, compare it with the original checksum. .tar.xz is an archive of multiple files, so it’s better to check the internal list first using tar -tJf.

Main Options and Format

Options/Format Description
-k Keep the compressed input file.
-c Sends the decompressed data to standard output.
-t Check the integrity of the compressed file.
-f Can forcibly overwrite existing target files.
-v Display processing status in detail.

Precautions when using

If you use -f or output redirection, the existing file may be corrupted, so check the target name. Using unxz alone will not extract all component files of .tar.xz. In automated scripts, explicitly using xz -d as recommended in official documentation helps with portability.

Frequently Asked Questions

What should I do after unxz backup.tar.xz?

The archive is decompressed, leaving backup.tar. Extract the internal files with tar -xf backup.tar.

Official Documentation

The exact behavior of options and differences depending on implementation can be found in the official documentation for unxz.

More in This Category
Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.

Linux getent Command: Query Users, Groups, and Other NSS Databases

Linux getent Command: Query Users, Groups, and Other NSS Databases

Learn how to query Users, Groups, and Other NSS Databases with the Linux getent command, including practical examples, key options, and important precautions.

Linux Disk Management: Partitioning, Formatting, and Mounting

Linux Disk Management: Partitioning, Formatting, and Mounting

Learn a safe Linux disk-management workflow for identifying devices, creating partitions and filesystems, mounting storage, and configuring persistent mounts.

Linux rpm Command: Inspect RPM Packages and the Installed Database

Linux rpm Command: Inspect RPM Packages and the Installed Database

Learn how to inspect RPM Packages and the Installed Database with the Linux rpm command, including practical examples, key options, and important precautions.

Linux chmod Command: Change File and Directory Permissions

Linux chmod Command: Change File and Directory Permissions

Learn how to change File and Directory Permissions with the Linux chmod command, including practical examples, key options, and important precautions.

Linux nc Command: Test TCP and UDP Connections

Linux nc Command: Test TCP and UDP Connections

Learn how to test TCP and UDP Connections with the Linux nc command, including practical examples, key options, and important precautions.

Linux comm Command: Compare Two Sorted Files

Linux comm Command: Compare Two Sorted Files

Learn how to compare Two Sorted Files with the Linux comm command, including practical examples, key options, and important precautions.

Linux machine-id: How to Check and Reset It for Cloned Systems

Linux machine-id: How to Check and Reset It for Cloned Systems

Learn what the Linux machine-id identifies, how to check it, and how to prepare cloned system images for unique IDs. Understand the difference between an empty file and first-boot initialization.

Linux timedatectl Command: Check Time Zone and Time Synchronization

Linux timedatectl Command: Check Time Zone and Time Synchronization

Learn how to check Time Zone and Time Synchronization with the Linux timedatectl command, including practical examples, key options, and important precautions.