what I usually do for things like this is to first use find
to make a list of files (e.g. find . -iname "pattern" > files.lst
then I use vi
on the list to rename them with the substitute command (similar to above). It can be a bit tricky when you have multiple characters as that means quite a number of groups and the regexp can also be difficult to get right. -- this is the sort of thing true sys admins do rather than crossword puzzles or whatnot ;-)
, you might want to look at using AWK
or something on the file of file names to pick up a line and loop through file name character by character to make desired changes. This would be easier if you used the printf option in find
to separate the path from the file name so you'd have a two field comma separated (e.g. find . -iname "pattern" -printf "\"%f\",\"%h\"\n > files.csv
), double quoted strings that AWK could parse and then process the file then output a line formatted as mv "filespec1" "filespec2"
, you can just make a file with find that you can edit manually. In this case, use the printf option %p twice with an mv on the front and escaped double quotes around the file name and a \n at the end.
either way, you'd get a shell script for the rename that you could examine to see if it was what you wanted before you tried it.
Also check the man page for rename
- you might be able to use that successively changing just one thing at a time.
of course, in things like this there is no more comfortable feeling that having a good backup in several forms readily available.
This topic and peoples solutions are a huge headache
I can sympathize with this! It is one of those simple sounding things that really isn't trivial.