Last Updated: January 19, 2020
· josefnpat

Recursively Expand Tabs to Spaces

Using the common find and the lesser known, expand, one can easily replace tabs with spaces. In this script, the current directory will be parsed, and all tabs will be replaced with two spaces.

# Recursively expand
find . -name $1 | while read line
  expand --tabs=2 $line > $line.tmp
  mv $line.tmp $line

Here is an example of parsing all *.lua files recursively in /path/to/foo/. The script is located at /path/to/script/

cd /path/too/foo/
/path/to/script/ *.lua