Linux expand Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux expand Guide
Complete beginner-friendly guide to expand on Linux, covering Arch Linux, CachyOS, and other distributions including converting tabs to spaces, text formatting, and whitespace conversion.
Table of Contents
expand Basics
Convert Tabs
Basic usage:
# Convert tabs to spaces
expand file.txt
# Converts tabs to spaces
Default Tab Width
Default behavior:
# Default: 8 spaces per tab
expand file.txt
# Converts tabs to 8 spaces
Tab to Space Conversion
Custom Width
Set tab width:
# Custom tab width
expand -t 4 file.txt
# -t = tabs (4 spaces per tab)
Multiple Tab Stops
Multiple stops:
# Multiple tab stops
expand -t 4,8,12 file.txt
# Tab stops at columns 4, 8, 12
Tab Stops
Single Width
Uniform width:
# All tabs = 4 spaces
expand -t 4 file.txt
# Every tab becomes 4 spaces
Variable Stops
Variable stops:
# Variable tab stops
expand -t 4,8,12 file.txt
# Different stops at different columns
File Processing
In Place
Modify file:
# In place (GNU extension)
expand -t 4 file.txt > file.txt.tmp
mv file.txt.tmp file.txt
# Or use sponge (from moreutils)
expand -t 4 file.txt | sponge file.txt
Output to File
Save to file:
# Output to file
expand -t 4 file.txt > output.txt
# Saves converted file
Troubleshooting
expand Not Found
Check installation:
# expand is part of coreutils
# Usually pre-installed
# Check expand
which expand
Summary
This guide covered expand usage, tab-to-space conversion, and text formatting for Arch Linux, CachyOS, and other distributions.
Next Steps
- unexpand Guide - Convert spaces to tabs
- sed Guide - Text processing
- Text Processing - Text manipulation
- expand Documentation:
man expand
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.