znew
Recompress .gz files to newer format
TLDR
Recompress a file from .Z to gzip format
Recompress multiple files and display the achieved size reduction % per file
Recompress a file using the slowest compression method (for optimal compression)
Recompress a file, [K]eeping the .Z file if it is smaller than the gzip file
SYNOPSIS
znew [ -9fv ] [ -p path ] [ -K ] [ name ... ]
PARAMETERS
-9, --best
Uses the slowest compression method, resulting in the highest possible compression ratio. This is equivalent to gzip -9.
-f, --force
Forces recompression even if a .gz file with the same name already exists, or if the original file has multiple links. Overwrites existing files without prompt.
-v, --verbose
Displays the name of each file being recompressed and the percentage reduction achieved.
-p path
Specifies an alternative path to the gzip program. Useful if gzip is not in the system's PATH or if a specific version is required.
-K, --keep
Keeps (does not delete) the original .Z file after successful recompression. By default, the original file is removed.
name ...
One or more names of files to be recompressed. If no file names are specified, znew reads file names from standard input, one per line.
DESCRIPTION
znew is a utility designed to efficiently convert files compressed with the older compress(1) utility (typically ending with a .Z extension) into the more modern and widely used gzip(1) format (ending with a .gz extension).
What makes znew particularly useful is its ability to perform this recompression without first decompressing the original .Z file. This significantly saves time, CPU cycles, and disk space, especially when dealing with large files. It achieves this by reading the compressed data, applying gzip's compression algorithms, and writing out the new .gz file, effectively translating the compression format on the fly.
It's often a symbolic link to the gzip executable itself, leveraging gzip's internal capabilities for this specific task. This command is valuable for migrating legacy compressed archives to a more universally compatible and often more efficient compression standard.
CAVEATS
znew renames files from a .Z extension to a .gz extension upon successful recompression. It does not handle directories recursively. Files with multiple hard links require the -f (force) option to be recompressed, and the original file will be deleted only if all links refer to the same inode. It is designed specifically for .Z (compress) files; it will not work on other compressed formats directly.
EFFICIENCY
The key advantage of znew is its efficiency. By avoiding the intermediate decompression step, it saves significant time and computational resources, making it ideal for converting large archives or a multitude of smaller ones.
UNDERLYING IMPLEMENTATION
In many Linux distributions, znew is not a standalone executable but rather a symbolic link to the gzip program. When invoked as znew, the gzip executable detects this invocation name and behaves accordingly, enabling its specialized recompression mode.
HISTORY
The znew command emerged as part of the gzip package, reflecting the transition in Unix-like systems from the older compress utility (which created .Z files) to the more efficient and widely adopted gzip. Its primary purpose was to facilitate the migration of existing .Z archives to the .gz format without the overhead of a two-step decompression and recompression process. This development made it easier for users and administrators to standardize on gzip while still managing legacy data.
SEE ALSO
gzip(1), compress(1), uncompress(1), zcat(1), zmore(1)