Skip to content

Instantly share code, notes, and snippets.

@dbswebsite
Last active December 21, 2020 11:59
Show Gist options
  • Save dbswebsite/f7ff88850dcf01fdafab5e66186cbdec to your computer and use it in GitHub Desktop.
Save dbswebsite/f7ff88850dcf01fdafab5e66186cbdec to your computer and use it in GitHub Desktop.
Normalize image filenames, recursively.
#!/bin/bash
#
# @file normalize.sh
#
# @requires the perl 'rename' utility
#
################################################################################
# force to lowercase
find . -iregex ".+\.\(jpe?g\|png\)" | rename 'y/A-Z/a-z/'
# replace evil whitespace with dash
find . -iregex ".+\.\(jpe?g\|png\)"| rename 's/ /-/g'
# remove other non-useful, possbily illegal chars
find . -iregex ".+\.\(jpe?g\|png\)" -printf "%P\n" | rename 's/[^-_\.\+ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]//g'
@halburgiss
Copy link

halburgiss commented May 13, 2016

Add first ...

find -type d | rename 's/ /-/g'
find -type d | rename 'y/A-Z/a-z/'

to fix any subdirectory names that might be fubar as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment