#!/usr/bin/env bash
# Removes all spaces from file and directory names recursively.
# Run from any directory; pass the target directory as an argument (defaults to .).
# find . -depth -name "* *" # to check
TARGET="${1:-.}"
# Process deepest paths first so parent renames don't break child paths.
find "$TARGET" -depth -name "* *" | while IFS= read -r path; do
dir=$(dirname "$path")
base=$(basename "$path")
new_base="${base// /}"
if [ "$base" != "$new_base" ]; then
mv -- "$path" "$dir/$new_base"
echo "Renamed: $path -> $dir/$new_base"
fi
done