Created
September 17, 2017 09:19
-
-
Save jandradap/9c0e13524d81dbde21130da61c33a80b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # rename-files.sh Files #Specify Directory Name | |
| #print usage | |
| if [ -z $1 ];then | |
| echo "Usage :$(basename $0) parent-directory" | |
| exit 1 | |
| fi | |
| #process all subdirectories and files in parent directory | |
| all="$(find $1 -depth)" | |
| for name in ${all}; do | |
| #set new name in lower case for files and directories | |
| new_name="$(dirname "${name}")/$(basename "${name}" | tr '[A-Z]' '[a-z]')" | |
| #check if new name already exists | |
| if [ "${name}" != "${new_name}" ]; then | |
| [ ! -e "${new_name}" ] && mv -T "${name}" "${new_name}"; echo "${name} was renamed to ${new_name}" || echo "${name} wasn't renamed!" | |
| fi | |
| done | |
| echo | |
| echo | |
| #list directories and file new names in lowercase | |
| echo "Directories and files with new names in lowercase letters" | |
| find $(echo $1 | tr 'A-Z' 'a-z') -depth | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment