expand(1)
Convert tabs to spaces in text files.
Synopsis
expand [OPTION]... [FILE]...Description
The expand command reads files (or standard input) and writes them to standard output with tab characters converted to spaces. By default, tabs are expanded to the next multiple of 8 columns, matching the standard tab stop positions.
This is useful for preparing text files for display on systems that don't handle tabs consistently, or for ensuring consistent formatting across different environments.
Common options
| Flag | What it does |
|---|---|
-t NUM | Set tab stops to every NUM columns (default: 8) |
-t LIST | Set custom tab stops (e.g., -t 4,8,12 or -t 4,+4) |
-i, --initial | Only expand tabs at the beginning of lines |
-a, --all | Expand all tabs, not just leading tabs (default behavior) |
--help | Display help message and exit |
--version | Output version information and exit |
Examples
Convert all tabs to spaces (8-column tabs) and print to stdout
expand file.txtExpand tabs to 4-column spacing and save to a new file
expand -t 4 file.txt > output.txtPipe file through expand with 2-column tab stops
cat file.txt | expand -t 2Only expand leading tabs (indentation) using 4-column stops
expand -i -t 4 script.shSet custom tab stop positions at columns 4, 8, 12, and 16
expand -t 4,8,12,16 data.txtSet first tab stop at column 4, then every 4 columns thereafter
expand -t 4,+4 file.txt