>_cmd.script

uncompress

Restore files compressed with the legacy .Z format

Compression

By CMD Script Team · 4 min read · Last updated

SYNTAX
uncompress [OPTIONS] FILE.Z

Options

Command options and flags
FlagDescription
-cWrite the decompressed output to stdout instead of a file, leaving FILE.Z untouched
-fForce overwrite of an existing output file without prompting
-vVerbose: report the percentage reduction for each file as it is restored
-VPrint 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 — decompress file.Z into file, removing the .Z file
  • uncompress -v file.Z — same, but print the percentage size reduction
  • uncompress -c file.Z > file — decompress to stdout, keeping file.Z in place
  • uncompress *.Z — decompress every .Z file in the current directory
uncompress -v legacy-dump.tar.Z

Advanced examples

  • Decompress an old tarball and pipe straight into tar without an intermediate file: uncompress -c backup.tar.Z | tar -xf -
  • Batch-restore a directory tree of .Z files 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 .Z file before committing disk space to a full decompress: zcat file.Z | head -n 20 (works only if your zcat/gzip build supports .Z)
uncompress -c old-release.tar.Z | tar -tvf - | head

Common mistakes

  • Assuming uncompress handles .gz or .bz2 files — it only understands the .Z LZW format; use gunzip or bunzip2 for 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 uncompress deletes the .Z file by default — always use -c first 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 .Z extension — check with file archive.Z first.

Tips

  • Use file somefile.Z to confirm it's genuinely a compress-format archive before running uncompress on it.
  • If disk space is tight, pipe directly into the consuming program (tar, cpio) via -c instead of materializing the decompressed file on disk.
  • Keep a copy of the original .Z file elsewhere before decompressing irreplaceable old archives, since uncompress removes the source file by default.

Best practices

  • Treat any .Z file you receive as a migration candidate: decompress it once, then recompress with gzip or xz for long-term storage — smaller footprint, faster tools, and no dependency on the increasingly rare ncompress package.
  • Always verify tool availability (which uncompress) in a script before relying on it in automation; prefer detecting and branching to gzip -d or xz -d for anything produced after the 1990s.
  • Document any pipeline step that depends on .Z support, 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 compress before gzip existed.
  • Migrating legacy build artifacts or datasets from old Solaris/SunOS or BSD systems that still use .Z compression.
  • One-off archaeology: extracting a .tar.Z file found on old install media or a dusty NFS share during a server decommission.

Common interview questions

  • What algorithm does .Z compression use, and how does it differ from gzip? .Z uses LZW (Lempel-Ziv-Welch); gzip uses DEFLATE (LZ77 + Huffman coding), which generally compresses better and faster.
  • How would you decompress a .Z file without deleting the original? uncompress -c file.Z > file writes to stdout, leaving file.Z in place.
  • Why might uncompress not be installed on a modern Linux system? Because the compress/uncompress pair has been replaced by gzip/bzip2/xz/zstd and 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.