Created
May 6, 2020 02:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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