Home·Terminal commands

expand

Text processing

Usage

expand -t 4 [file]

Turns tab characters into spaces; a Makefile needs real tabs to work, so running expand on one breaks the build.

Common flags

FlagMeaning
-tTab width, or a comma-separated list of tab stops
-iGNU: convert only the tabs at the start of a line
unexpand -aThe reverse: turn runs of spaces back into tabs

Examples

expand -t 2 old.py

Turns each tab into two spaces.

unexpand -a -t 4 file.txt

Turns every four spaces back into a tab.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does expand do?

Turns tab characters into spaces; a Makefile needs real tabs to work, so running expand on one breaks the build.

Q. How do I type it?

expand -t 4 [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

3 are listed here; the full set is in man expand. This command sits under Text processing.

Related commands

man page: man expand