Compress and decompress single files with xz for high compression ratios and tight storage. 01.06.2026 | reading time: 2 min The xz command uses the LZMA2 algorithm to deliver high compression ratios for single files; learn when to trade CPU for space and how to operate xz from the shell. Quick demo: compress and restore Create a test file, compress it, inspect sizes, then restore it: ```bash $ for i in {1..1000}; do echo "line $i" >> sample.txt; done $ ls -lh sample.txt -rw-r--r-- 1 user user 12K sample.txt $ xz -z sample.txt $ ls -lh sample.txt.xz -rw-r--r-- 1 user user 3.2K sample.txt.xz $ xz -d sample.txt.xz $ ls -lh sample.txt -rw-r--r-- 1 user user 12K sample.txt ``` Tune compression and performance Use `-0` to `-9` to change compression level and `-T` to control threads (for example `-T0` auto-selects cores); keep the original with `-k`, stream data with `xz -c`, and combine with `tar` as `tar -cJf archive.tar.xz` for multi-file archives. Useful companion commands Read compressed data without extracting using `xzcat`, test archives with `xz -t`, force decompression with `xz -d` or `unxz`, and pipe data between processes to avoid temporary files for faster workflows. Wrap-up and next step xz is a great fit when disk or transfer size is the limiting factor; experiment with levels and threads to find the sweet spot for your workload and then move on to mastering related tools and system skills at bitsandbytes.academy to prepare for certifications like CompTIA Linux+ or LPIC-1. Join Bits & Bytes Academy First class LINUX exam preparation. utilities storage backup