Skip to content

Instantly share code, notes, and snippets.

@attentive
Created February 10, 2022 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attentive/09793ac0d8e17fdf0fb897d478246b4c to your computer and use it in GitHub Desktop.
Save attentive/09793ac0d8e17fdf0fb897d478246b4c to your computer and use it in GitHub Desktop.
Rename a filesystem where directories and files have some consistent prefix, with only the utilities available to msysGit Bash on Windows
#!/bin/sh
# Do all the directories first
find . -name 'SomePrefix*' -type d | awk '{print "mv "$0" "gensub(/\/SomePrefix(.*)$/,"/SomeOtherPrefix\\1","g");}' | sh
# Then do all the files
find . -name 'SomePrefix*' -type f | awk '{print "mv "$0" "gensub(/\/SomePrefix(.*)$/,"/SomeOtherPrefix\\1","g");}' | sh
@attentive
Copy link
Author

Just putting this here because it's a wee bit magical and despite the relative obviousness of how it works, also surprisingly tricky to perfect anew each time I need it.

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