Did you know?
unxz deletes the .xz file after decompressing it unless you add -k.
Use unxz -k (or xz -dk) to keep the compressed copy, and xzcat to read it without unpacking.
- Files & directories
- Last checked
Explained
Like gzip and bzip2, the XZ tools replace the file they work on. Run unxz backup.sql.xz and you get backup.sql, but backup.sql.xz is gone. That is a surprise when the compressed file is the only copy you meant to keep, or when you still need it to send somewhere else.
Add -k (--keep) to keep the original:
unxz -k backup.sql.xz
ls backup.sql*
backup.sql backup.sql.xzThe same flag works for xz -dk and when compressing: xz -k file creates file.xz and leaves file in place. If the output file already exists, unxz stops with “File exists”; add -f to overwrite it.
If you only want to read the data, you don’t need to decompress at all: xzcat, xzless and xzgrep read the .xz file directly and never touch it. tar -xf archive.tar.xz also leaves the archive alone.
Learn more
- How to Extract .tar.xz and .xz Files in Linux, macOS & Windows Full guide · Updated Nov 2026
-
tarcommand cheat sheet Options and copy-ready examples
