uncompress
Restore files compressed with the legacy .Z format
By CMD Script Team · 4 min read · Last updated
uncompress [OPTIONS] FILE.ZOptions
| Flag | Description |
|---|---|
-c | Write the decompressed output to stdout instead of a file, leaving FILE.Z untouched |
-f | Force overwrite of an existing output file without prompting |
-v | Verbose: report the percentage reduction for each file as it is restored |
-V | Print the version/copyright information for the compress/uncompress utility |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS
What it does
uncompress reverses the compression applied by the classic Unix compress utility,
which produces files with a .Z extension using the LZW (Lempel-Ziv-Welch) algorithm.
Running uncompress file.Z restores file and, by default, removes the .Z file — the
same replace-in-place behavior gunzip uses for .gz files. It is a legacy tool: .Z
compression predates gzip by years and offers noticeably worse compression ratios, so
you'll typically only reach for uncompress when you're handed an old archive rather
than when creating new compressed files yourself.
Beginner examples
uncompress file.Z— decompressfile.Zintofile, removing the.Zfileuncompress -v file.Z— same, but print the percentage size reductionuncompress -c file.Z > file— decompress to stdout, keepingfile.Zin placeuncompress *.Z— decompress every.Zfile in the current directory
uncompress -v legacy-dump.tar.Z
Advanced examples
- Decompress an old tarball and pipe straight into
tarwithout an intermediate file:uncompress -c backup.tar.Z | tar -xf - - Batch-restore a directory tree of
.Zfiles while keeping originals for safety:find . -name "*.Z" -exec uncompress -c {} \; > /dev/null(better: loop with redirection per file) - Force-decompress over an existing extracted copy after a failed prior attempt:
uncompress -f partially-restored.Z - Check what's inside a
.Zfile before committing disk space to a full decompress:zcat file.Z | head -n 20(works only if yourzcat/gzipbuild supports.Z)
uncompress -c old-release.tar.Z | tar -tvf - | head
Common mistakes
- Assuming
uncompresshandles.gzor.bz2files — it only understands the.ZLZW format; usegunziporbunzip2for those. - Not realizing the tool may be missing entirely on a fresh install (it's often bundled
separately as
ncompress), leading to a confusing "command not found." - Forgetting that
uncompressdeletes the.Zfile by default — always use-cfirst if you're unsure the archive is intact and want to keep the original. - Trying to decompress a file that isn't actually
.Z-formatted just because it has a.Zextension — check withfile archive.Zfirst.
Tips
- Use
file somefile.Zto confirm it's genuinely acompress-format archive before runninguncompresson it. - If disk space is tight, pipe directly into the consuming program (
tar,cpio) via-cinstead of materializing the decompressed file on disk. - Keep a copy of the original
.Zfile elsewhere before decompressing irreplaceable old archives, sinceuncompressremoves the source file by default.
Best practices
- Treat any
.Zfile you receive as a migration candidate: decompress it once, then recompress withgziporxzfor long-term storage — smaller footprint, faster tools, and no dependency on the increasingly rarencompresspackage. - Always verify tool availability (
which uncompress) in a script before relying on it in automation; prefer detecting and branching togzip -dorxz -dfor anything produced after the 1990s. - Document any pipeline step that depends on
.Zsupport, since it's an unusual dependency reviewers may not expect.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Restoring decades-old Unix system backups or vendor software distributions that were
archived with
compressbeforegzipexisted. - Migrating legacy build artifacts or datasets from old Solaris/SunOS or BSD systems that
still use
.Zcompression. - One-off archaeology: extracting a
.tar.Zfile found on old install media or a dusty NFS share during a server decommission.
Common interview questions
- What algorithm does
.Zcompression use, and how does it differ fromgzip?.Zuses LZW (Lempel-Ziv-Welch);gzipuses DEFLATE (LZ77 + Huffman coding), which generally compresses better and faster. - How would you decompress a
.Zfile without deleting the original?uncompress -c file.Z > filewrites to stdout, leavingfile.Zin place. - Why might
uncompressnot be installed on a modern Linux system? Because thecompress/uncompresspair has been replaced bygzip/bzip2/xz/zstdand is now often packaged separately (e.g.,ncompress) rather than installed by default.
Frequently Asked Questions
Is uncompress still relevant today?
Barely. The .Z format (LZW compression via the old compress utility) has been superseded by gzip, bzip2, xz, and zstd, which compress better and are installed by default. You'll mostly meet .Z files in old archives, legacy Unix tarballs, or ancient software distributions.
Why isn't uncompress installed on my system?
Many modern distros no longer ship the compress/uncompress pair by default. On Debian/Ubuntu install the `ncompress` package (apt install ncompress); on Fedora `dnf install ncompress`; on Arch `pacman -S ncompress`. macOS still ships compress/uncompress as part of the base system.
What's the difference between uncompress and gunzip?
uncompress reverses the old LZW-based .Z format produced by compress. gunzip reverses the DEFLATE-based .gz format produced by gzip. They are not interchangeable — running uncompress on a .gz file (or vice versa) fails.
Can I just use gzip to decompress a .Z file?
No. Even though both tools live in the same 'era' of compression, gzip cannot decode the LZW .Z format. Use uncompress, or `zcat` if your build of zcat/gzip was compiled with .Z support (many are not).
Cheat sheet
Download a quick-reference cheat sheet for uncompress.