Skip to content

Instantly share code, notes, and snippets.

@raws
Created July 15, 2012 17:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raws/3117772 to your computer and use it in GitHub Desktop.
Save raws/3117772 to your computer and use it in GitHub Desktop.
Bash helper script for recursively lowercasing file names
#!/bin/bash
#
# downcase PATH
#
# Recursively convert all file names contained in the given directory
# tree (but excluding the given directory itself) to lowercase.
# Existing files which are named identical to new, lowercased file
# names will be clobbered.
#
# Author: Ross Paffett <ross@rosspaffett.com>
# Inspiration: http://stackoverflow.com/a/152836
if [ -n "$1" ]; then
find "$1" -depth -mindepth 1 \( -type d -or -type f \) -print0 | xargs -0n 1 bash -c \
'src=$(dirname "$0")/$(basename "$0");
dst=$(dirname "$0")/$(basename "$0" | tr "[A-Z]" "[a-z]");
mv -fv "$src" "$dst"'
else
echo "usage: downcase PATH"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment