Linux unexpand Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki

Linux unexpand Guide

Complete beginner-friendly guide to unexpand on Linux, covering Arch Linux, CachyOS, and other distributions including converting spaces to tabs, text formatting, and whitespace conversion.


Table of Contents

  1. unexpand Basics
  2. Space to Tab Conversion
  3. Tab Stops
  4. File Processing
  5. Troubleshooting

unexpand Basics

Convert Spaces

Basic usage:

# Convert spaces to tabs
unexpand file.txt

# Converts leading spaces to tabs

Default Behavior

Leading spaces:

# Only leading spaces
unexpand file.txt

# Converts leading spaces to tabs

Space to Tab Conversion

All Spaces

Convert all:

# Convert all spaces
unexpand -a file.txt

# -a = all (converts all spaces)

Leading Only

Default (leading):

# Leading spaces only (default)
unexpand file.txt

# Only converts leading spaces

Tab Stops

Custom Tab Stops

Set tab width:

# Custom tab stops
unexpand -t 4 file.txt

# -t = tabs (4 spaces per tab)

Multiple Stops

Multiple stops:

# Multiple tab stops
unexpand -t 4,8,12 file.txt

# Tab stops at columns 4, 8, 12

File Processing

In Place

Modify file:

# In place (GNU extension)
unexpand -a file.txt > file.txt.tmp
mv file.txt.tmp file.txt

# Or use sponge (from moreutils)
unexpand -a file.txt | sponge file.txt

Output to File

Save to file:

# Output to file
unexpand -a file.txt > output.txt

# Saves converted file

Troubleshooting

unexpand Not Found

Check installation:

# unexpand is part of coreutils
# Usually pre-installed

# Check unexpand
which unexpand

Summary

This guide covered unexpand usage, space-to-tab conversion, and text formatting for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.