Skip to content

Instantly share code, notes, and snippets.

@franckweb
Created May 6, 2020 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franckweb/493beb20d8b839699df24fa5f1e9c653 to your computer and use it in GitHub Desktop.
Save franckweb/493beb20d8b839699df24fa5f1e9c653 to your computer and use it in GitHub Desktop.
Bash script to bulk rename subdirectories to lowercase and change spaces for underscore
#!/bin/bash
# use: "bash bulk_dir_rename.sh path"
source_dir=$1
for found_dir in $source_dir/*;
do
original_dir_name=$(basename "${found_dir}")
lowercase_name=${original_dir_name,,}
no_space_dir=$(echo "$lowercase_name" | sed -e 's/ /_/g')
if [[ "${found_dir}" != "${source_dir}/${no_space_dir}" ]]; then
mv "${found_dir}" "${source_dir}/${no_space_dir}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment