Advertisement
Guest User

LowerIt non-recursive

a guest
Mar 14th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. ##
  3. ## "LowerIt"
  4. ##
  5. ## Original code found here:  http://www.linuxjournal.com/content/convert-filenames-lowercase
  6. ## Modified by Maiya78 to change directory names, to work recursively, and to support unicode filenames on GNU systems.  I also copyedited the comments.  :3
  7. ##
  8. ## From the current directory, recursively convert to lower case all file and directory names
  9. ## Should ask for verification before overwriting an existing file.  
  10. ##
  11. ## ------------------------------------------------------------------------------------------------------------
  12. ## Clean up aliases
  13. unset pwd && unset export && unset cd && unset echo && unset ls && unset sd && unset mv
  14. ## Make sure we're in the right directory
  15. export strDir=$(pwd)
  16. cd $strDir
  17. echo "Entering current directory:  "$strDir
  18. ## Need to make a loop or something here that repeats this for every subdirectory ad nauseum
  19.  
  20. ## Show the user what's in the current directory pre-edit
  21. echo "
  22. Current directory before edit:  " && ls -a
  23. ## Start the editing loop
  24. for strItem in $(ls -a)
  25. do
  26. ## Save the computer some breath on . and ..
  27. #    if [[ $strItem != '.' || '..' ]]; then
  28. #        continue
  29. #    fi
  30. ## Set a variable equal to the lowercased vesion of the original filename
  31.     strLowerCasedItem=$(echo $strItem | sed 's/[[:upper:]]*/\L&/')
  32. ## If this variable is the same as the original, then the original was already lowercased, so we skip it.  
  33.     if [[ $strLowerCasedItem != $strItem ]]; then
  34.         mv -i $(echo $strDir'/'$strItem) $(echo $strDir'/'$strLowerCasedItem)
  35.     fi
  36. done
  37. ## Show the user what's in the current directory post-edit
  38. echo "
  39. Current directory after edit:  " && ls -a
  40. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement