LinuxCommandLibrary

gzexe

Compress executables and make them self-extracting

TLDR

Compress an executable file in-place

$ gzexe [path/to/executable]
copy

[d]ecompress a compressed executable in-place (i.e. convert the shell script back to an uncompressed binary)
$ gzexe -d [path/to/compressed_executable]
copy

SYNOPSIS

gzexe [-d] [-k] [-v] [--help] [--version] [name ...]

PARAMETERS

-d
    Decompress gzexe'd files, restoring originals

-k
    Keep input files instead of replacing them

-v
    Enable verbose output during processing

--help
    Display usage summary and exit

--version
    Print version info and exit

DESCRIPTION

gzexe is a utility from the GNU gzip package designed to compress Unix/Linux executable files. It replaces the original binary with a compact shell script that automatically decompresses the executable to a temporary file upon invocation, executes it, and then removes the temp file. This approach leverages gzip compression to reduce disk space usage for large, infrequently-run programs.

The process is transparent to users: after compression, the file retains its original name and permissions, and runs identically (after the initial decompression overhead). It's particularly useful on embedded systems, archival storage, or space-limited environments where executables are rarely executed.

However, gzexe is not ideal for production servers or performance-critical applications. Every execution incurs a decompression delay (typically 10-500ms depending on file size), and the wrapper script introduces minor security risks, such as reliance on shell execution. Compressed files start with a gzip header followed by the unpacking script, making them recognizable and sometimes flagged by antivirus tools.

To reverse, use gzexe -d. Supports multiple files or directories recursively if patterns match executables.

CAVEATS

gzexe adds startup latency from decompression on every run.
Avoid on setuid/setgid binaries, scripts, or frequent-execution programs.
May fail on non-standard executables; antivirus often flags self-extractors.
Small files may grow larger due to script overhead.

BASIC USAGE

gzexe myprog
Replaces myprog with compressed self-extractor.

gzexe -d myprog
Decompresses back to original binary.

HOW IT WORKS

Creates script like: #!/bin/sh gzip -cd "$0" | gzip -d >$0~; exec $0~; rm $0~.
Executable data follows gzip header.

HISTORY

Developed by Jean-loup Gailly for GNU gzip; first appeared in version 1.2.4 (May 1993). Remains in modern gzip releases (e.g., 1.12+) for legacy space-saving needs, though alternatives like UPX are preferred today.

SEE ALSO

gzip(1), gunzip(1), upx(1), strip(1)

Copied to clipboard