Created
February 10, 2022 02:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.