Skip to content

Instantly share code, notes, and snippets.

@pleasetrythisathome
Created December 2, 2014 20:45
Show Gist options
  • Save pleasetrythisathome/1a98e329a08cd0fd47bb to your computer and use it in GitHub Desktop.
Save pleasetrythisathome/1a98e329a08cd0fd47bb to your computer and use it in GitHub Desktop.
bash clean filenames
# convert all spaces to underscores, remove characters like {}(),\! and convert the filename to lowercase.
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
# just spaces to underscores
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' `
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment