Skip to content

Instantly share code, notes, and snippets.

@shapeshed
Created February 3, 2009 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shapeshed/57526 to your computer and use it in GitHub Desktop.
Save shapeshed/57526 to your computer and use it in GitHub Desktop.
Bash script to convert all filename in a folder to lowercase and replace spaces with underscores
#!/bin/bash
# Replaces spaces in filenames with underscores and converts filenames to lowercase
# Run within a directory to convert all files
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment