Skip to content

Instantly share code, notes, and snippets.

@huevos-y-bacon
Created August 20, 2024 16:08
Show Gist options
  • Save huevos-y-bacon/e880b2b31d18bcf876b161c74ebe691d to your computer and use it in GitHub Desktop.
Save huevos-y-bacon/e880b2b31d18bcf876b161c74ebe691d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Rename all directories (not files) in the current directory to lowercase, Replace underscores and spaces with hyphens
# Find all directories in the current directory and rename them
find . -maxdepth 1 -mindepth 1 -type d | while read -r d; do
# strip leading ./ and trailing /
d=$(basename "$d")
d2=$(echo "$d" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr '_' '-')
if [ "$d" != "$d2" ]; then
echo "Renaming $d to $d2"
mv "$d" "$d2"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment