maux
Star on GitHub Buy me a coffee

Manual / unexpand

unexpand(1)

UNEXPAND(1) General Commands Manual UNEXPAND(1)

unexpand - convert spaces to tabs

unexpand [ -a ] [ -t tablist ] [ file ] ...

Unexpand copies each named file (standard input if none is given) to standard output, replacing runs of two or more blanks that reach a tab stop with a tab.

Without -a or -t, only a leading run — one starting at the very first column of the line — is a candidate; the instant a non-blank byte is seen, the rest of that line is copied through untouched. -a converts a qualifying run anywhere in the line, not just a leading one; a bare -t implies -a.

Tablist is as for expand(1): a single number sets periodic stops that many columns apart (8 by default); two or more increasing numbers set explicit stops, past which no further run can qualify.

A run that crosses more than one stop collapses one tab per stop crossed, not one tab for the whole run; any blanks left over that never reach a stop stay literal. A run of exactly one blank is never converted, even sitting exactly on a stop — there is no length saved. A backspace counts as a member of the current run (its own column effect is -1, never below 0) without itself ending the run. The column resets at the start of each operand.

/usr/man/UNEXPAND this page

expand(1), fold(1), cut(1)

Exit status is 0; 1 if a file named on the command line could not be opened — that file is skipped, a diagnostic naming it is written to standard error, and the remaining operands are still processed; 2 for a usage error, including a malformed or non-increasing tablist or a stop over 120.

An explicit tab stop is capped at 120 columns, the same ceiling as expand(1)'s own.

September 14, 2026 maux