← All commands
THE COMMAND REFERENCE

gzexe

Compress a program so that it unpacks itself each time it runs.

Last updated

Portable / common

Implementation-level reference; examples are not certified for every installed version.

Overview

gzexe replaces an executable with a compressed copy that decompresses itself when it is run. The program still works as before, but takes less disk space and starts a little slower. It keeps the original under the same name with a ~ added. It is of use only on small disks, and it is not suited to modern systems with shared libraries.

Background

The macOS manual says gzexe uses gzip to compress executables, producing executables that decompress on the fly. Today the name covers the GNU gzip script gzexe and the gzexe on macOS. The BusyBox 1.37.0 build used for this page has no gzexe applet.

Examples

Compress a small script; it still runs:

printf '#!/bin/sh\necho hi\n' > prog && chmod +x prog && gzexe prog > /dev/null 2>&1 && ./prog

The original is kept as prog~:

printf '#!/bin/sh\necho hi\n' > prog && chmod +x prog && gzexe prog > /dev/null 2>&1 && ls prog*

Common mistakes

A tiny file gets bigger, as the message -11.1% in the check shows, because the unpacking code is longer than what it saves. The compressed program needs gzip at run time, and each start unpacks it again into a temporary file, which slows it down. It does not work on programs that cannot run from a temporary file. The -d option that restores the original did not work on the macOS release tested.

Portability

This page has no BusyBox view: BusyBox has no gzexe applet. The examples hide the messages, which differ. The GNU versions are shell scripts, which the implementation probe never runs, so they are not identified automatically; the Linux guest ran them anyway. The Common examples were executed on GNU gzip scripts in the Linux guest and macOS system tools (see the development guide for the exact check).

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.