Session and utilities
The unxz command
Decompresses .xz files; it is xz --decompress under another name.
Most useful options
-k, --keepKeeps the .xz after decompressing it. Without it, it is deleted after a successful run-c, --stdoutWrites the result to standard output and does not create the file-f, --forceDeletes the target if it already exists and replaces it. Careful: its contents are lost-t, --testChecks integrity without extracting anything or creating files-T, --threads <n>Uses several threads since xz 5.4. It only helps if the file was compressed in blocksCopy-ready examples
$ printf 'texto\n' > f.txt && xz -k f.txt && unxz -c f.txt.xzcompresses and shows the content of the .xz without creating f.txt again.Example output
texto
$ unxz -t f.txt.xz && echo integrochecks the file without decompressing it to disk.Example output
integro
$ unxz -c f.txt.xz | wc -ccounts the bytes of the decompressed content.Example output
6
$ unxz -f -k f.txt.xzdecompresses and replaces f.txt if it exists. Warning: it overwrites the contents of f.txt without asking.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| unxz: f.txt: File exists | The file that decompression would produce already exists in the folder, and unxz does not replace it. | Rename the existing one or use -f if you want to replace it. |
| unxz: f.txt: File format not recognized | unxz tries to read the file as xz and its content is not. If it is already text, it does not need decompressing. | Check the type with file f.txt. If it is text, use it as it is. |
Typical mistakes
- unxz deletes the .xz after a successful decompression. Use -k if you want to keep it.
- If the target already exists, unxz stops with File exists and does not overwrite anything without -f.
- unxz only understands .xz, .lzma and, since xz 5.4, .lz. A .gz or a .zip is rejected.
Differences from similar commands
FAQ
Can unxz handle .lzma?
Yes. xz recognizes .lzma when decompressing, and .lz since version 5.4. unlzma is an alias of xz --format=lzma --decompress.
How do I decompress several .xz files at once?
Pass them all: unxz *.xz. Each one is processed separately and, without -k, its .xz disappears after a successful run.
What do I do if the .xz arrived incomplete?
Check with unxz -t. If it fails, the file is damaged or cut short and it is better to get a new copy, because this command does not repair it.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course