Chris Sedlmayr Real World Development

16Mar/101

Renaming multiple files by rule

I recently had the need to rename a bunch of files according to a simple rule.
In the directory, any files that had a prefix of "Gee_" should have the prefix changed to "Kif_"
After a little digging I found a simple but quite tasty solution.
Simply run this at your cli.

 
for f in Gee_*; do mv "$f" "Kif_${f#Gee_}"; done

Job done. It finds files matching the pattern supplied, then loops through renaming them appropriately.

It's worth noting this isn't recursive so will only complete for files in your current directory.

Filed under: sysad Leave a comment
Comments (1) Trackbacks (0)

Leave a comment


No trackbacks yet.