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 ip Command: Inspect and Configure Network Interfaces and Routes

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Learn how to inspect and Configure Network Interfaces and Routes with the Linux ip command, including practical examples, key options, and important precautions.

Linux last Command: Review Login and Reboot History

Linux last Command: Review Login and Reboot History

Learn how to use the Linux last command to review user login sessions, system reboots, and shutdown history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux uname Command: Check Kernel and System Architecture

Linux uname Command: Check Kernel and System Architecture

Learn how to check Kernel and System Architecture with the Linux uname command, including practical examples, key options, and important precautions.

Linux unzip Command: List and Extract ZIP Archives

Linux unzip Command: List and Extract ZIP Archives

Learn how to list and Extract ZIP Archives with the Linux unzip command, including practical examples, key options, and important precautions.

Linux which Command: Find Executables in PATH

Linux which Command: Find Executables in PATH

Learn how Linux which searches PATH for executables, shows all matching paths, differs from type and command -v, and should be used carefully in scripts.

Linux Administration Memo: Essential Commands and System Checks

Linux Administration Memo: Essential Commands and System Checks

A compact Linux administration reference for checking system information, processes, storage, networking, users, permissions, services, and logs.

Linux cat Command: Display and Concatenate File Contents

Linux cat Command: Display and Concatenate File Contents

Learn how to use the Linux cat command to display text files, concatenate multiple files, number lines, reveal hidden characters, and avoid unsafe redirection mistakes.

Linux Tutorial / Understand Users, Groups, and File Ownership

Linux Tutorial / Understand Users, Groups, and File Ownership

Understand UIDs, GIDs, primary and supplementary groups, and file ownership, then inspect them safely with id, groups, getent, ls, and stat.

Linux file Command: Identify File Types and Formats

Linux file Command: Identify File Types and Formats

Learn how to use the Linux file command to identify file formats from their contents instead of filename extensions, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux watch Command: Run a Command Repeatedly

Linux watch Command: Run a Command Repeatedly

Learn how to use the Linux watch command to rerun a command at regular intervals and highlight changing output, with essential options, practical examples, output interpretation, and common troubleshooting tips.