Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ##
- ## "LowerIt"
- ##
- ## Original code found here: http://www.linuxjournal.com/content/convert-filenames-lowercase ; though this looks nothing like it.
- ## Modified by Maiya78 to change directory names, to work recursively, and to support unicode filenames on GNU systems. I also copyedited the comments. :3
- ##
- ## From the current directory, recursively convert to lower case all file and directory names
- ## Should ask for verification before overwriting an existing file.
- ##
- ## ------------------------------------------------------------------------------------------------------------
- ## Clean up aliases
- unset pwd && unset export && unset cd && unset echo && unset sed && unset mv
- ## Make sure we're in the right directory
- export strStartDir=$(pwd)
- cd $strStartDir
- ## Write in a function the loop that we'll use for to edit the files
- function editingloop {
- if [[ -d $strDir ]]; then
- cd $strDir
- ## Check to make sure current directory isn't empty
- # if [[ $(echo $strDir/*) != $(echo $strDir'/*') ]]; then ## Doesn't seem to be working. :\
- echo "
- _______________________________________________________________________
- Entering current directory: "$strDir
- echo ''
- echo "Current directory before edit: " && echo $strDir/* | sed 's/ /\n/g' | sed 's!.*/!!' | tr '\r\n' ' '
- ## Start the editing loop
- for strItem in $(ls -a); do
- ## Save the computer some breath on . and ..
- # if [[ $strItem != '.' || '..' ]]; then ## Doesn't seem to be working. :\
- ## Set a variable equal to the lowercased vesion of the original filename
- strLowerCasedItem=$(echo $strItem | sed 's/[[:upper:]]*/\L&/')
- ## If this variable is the same as the original, then the original was already lowercased, so we skip it.
- if [[ $strLowerCasedItem != $strItem ]]; then
- mv -i $(echo $strDir'/'$strItem) $(echo $strDir'/'$strLowerCasedItem) ## '-i' makes sure that we check the user before clobbering
- fi
- # fi
- done
- echo '
- '
- echo "Current directory after edit: " && echo $strDir/* | sed 's/ /\n/g' | sed 's!.*/!!' | tr '\r\n' ' '
- echo ''
- # fi
- fi
- }
- ## Lowercase all items in the starting directory
- editingloop
- ## This loops the main loop through each subdirectory of the starting directory
- for strDir in $(echo $strStartDir/*); do
- editingloop
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement