How to Uncompress .Z File in Linux

Featured banner: Uncompress .Z Files in Linux

A .Z file is a compressed archive created with the Unix compress command and the LZW algorithm. When a download, backup script, or old software dump hands you a file ending in .Z, this tutorial shows you how to get your data back with uncompress, gzip -d, or znew.

What is a .Z file?

The .Z extension marks a file compressed with the classic Unix compress utility, which uses Lempel-Ziv-Welch (LZW) compression. The format predates gzip and shows up most often in old Unix documentation, source dumps, log archives, and legacy backups.

You can identify one with the file command:

file server.log.Z
server.log.Z: compress'd data 16 bits

The “16 bits” part is the maximum number of bits compress used for its dictionary entries. If file reports anything else, the file may be corrupt or misnamed, so check it before blaming the tools.

Method 1: Using the uncompress command

uncompress ships in the ncompress package on Debian and Ubuntu systems, so install it first:

sudo apt update && sudo apt install ncompress
Install Ncompress
Install Ncompress

On RHEL-based distributions use sudo dnf install ncompress or sudo yum install ncompress, and on Arch Linux use an AUR helper since ncompress is not in the official repositories.

Navigate to the directory holding your file, then run uncompress with the filename:

cd /path-to-directory-where-Z-file-is-located
uncompress -v server.log.Z
Uncompress .Z File
Uncompress Command

The -v flag prints what happened. On my Ubuntu 24.04 test box, a 26 KB log compressed to 2.3 KB decompressed back to its full size like this:

server.log:	 91.1% -- replaced with server.log
Uncompressed Z File
Uncompressed Z File

Two behaviors are worth knowing before you run it. uncompress deletes the .Z file after writing the uncompressed copy, so add -k if you want both kept.

If a file would not shrink, compress stores it unchanged, and uncompress refuses those with “not in compressed format”. Use uncompress -f to force the rename anyway.

Method 2: Using gzip -d

gzip understands the LZW-based .Z format directly, which makes this the fastest option because gzip is already installed on nearly every distribution. No package installation needed.

Run gzip with the decompress flag against your .Z file:

gzip -d -v server.log.Z
Gzip Dcompress Command
Gzip Dcompress Command

The output mirrors uncompress -v:

server.log.Z:	 91.1% -- replaced with server.log

Like uncompress, gzip replaces the .Z file with the decompressed original. Pass -k to keep the archive. You can also inspect a .Z file without extracting it by piping through zcat:

zcat server.log.Z | less

Bonus: Convert .Z to .gz with znew

If you plan to keep an archived file long-term, convert it from the obsolete .Z format to modern gzip instead of leaving it as-is. The znew tool, included with gzip, does this in one step:

znew -v server.log.Z
server.log:	 99.4% -- replaced with server.log.gz

In my run the same 26 KB file shrank further from 2.3 KB as .Z to just under 200 bytes as .gz, since gzip’s Deflate algorithm beats LZW on repetitive text. The result stays fully compatible with tar pipelines and every unzip-style tool built in the last three decades.

Unzip .z File Linux
Unzip .z File Linux

Which method should you pick?

  • uncompress: matches how the file was made, useful when scripting around legacy workflows that expect the same binary.
  • gzip -d: the default choice. Already installed, works everywhere, no extra package.
  • zcat: when you only need to read the contents without saving a new file.
  • znew: when you intend to keep the file and want it in the current standard format.

Conclusion

Any .Z file you meet today decompresses in one command: gzip -d file.Z is the shortest path, uncompress file.Z gives you the historically exact tool, and znew converts old archives to .gz for good. For more compression work, see our guide to fixing the gzip stdin not in gzip format error, how to bulk unzip multiple files in Linux, and our gzip command reference for everyday flags.