Skip to content

Instantly share code, notes, and snippets.

@atz
Last active July 28, 2018 06:56
Show Gist options
  • Save atz/972ef28b246b658b45f5f453459fb71c to your computer and use it in GitHub Desktop.
Save atz/972ef28b246b658b45f5f453459fb71c to your computer and use it in GitHub Desktop.
File renaming for Nicole
find . -type f -name [0-9]* .      # only files starting w/ digits
find . -type f -name [0-9]*.mp3    # only files starting w/ digits, ending in ".mp3"
find . -type f -name "[0-9]x[0-9] - *.mp3"        # ex. "1x01 - Original Pilot.mp3"
find . -type f -name "[0-9][0-9] *.mp3"           # ex. "01 Brave.mp3"
find . -type f -name "[0-9][0-9]-[0-9][0-9]*.mp3" # ex. "01-05Everywhere.mp3"
...
find . -type f -name "[0-9]x[0-9] - *.mp3" -o -name "[0-9][0-9] *.mp3" -0 -name "[0-9][0-9]-[0-9][0-9]*.mp3" # catch'm all

find . -type f -name "[0-9]x[0-9] - *.mp3" -exec rename 's/\/\d+x\d+ - ([^\/]*)$/\/$1/' {} \;      # /x/y/Original Pilot.mp3
find . -type f -name "[0-9][0-9] *.mp3" -exec rename 's/\/\d+ ([^\/]*)$/\/$1/' {} \;               # /x/y/Brave.mp3
find . -type f -name "[0-9][0-9]-[0-9][0-9]*.mp3" -exec rename 's/\/\d+-\d+ ([^\/]*)$/\/$1/' {} \; # /x/y/Everywhere.mp3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment