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.

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.