find . -type f -name '*authors-name-string*' -exec bash -c 'mv "$0" "${0/authors-name-string/}"' {} \;
I am trying to rename files nested in several layers of directories that contain an author's name text string embedded somewhat randomly in the filename. Creating a new filename that starts with the author's name followed by the rest of the original filename ... but sans the authors name string that was located in a somewhat random location in the original filename.
The shell command line above will recursively remove the authors-name-text string from the filename, but I have not figured out how to do that AND prepend the authors-name-text (and a trailing "_" underscore) to the start of the filename. Basically I want to move the authors-name-text from wherever it is currently in the filename to being at the beginning of the filename (plus an underscore). As far as I can tell the bash version invoked is v4.3 on my Synology NAS. I've logged in via ssh from my MacBook.
Trying to take thousands of files in different directories organized by subject directory name so that some of the files written by the same author inside the directories appear grouped together when viewing a simple directory listing.
find . -type f -name '*authors-name-string*' -exec bash -c 'mv "$0" "authors-name-string_${0/authors-name-string/}"' {} \;
The above command line fails when it tries to insert the "authors-name-string_" at the front of the entire filename pathway. Since there isn't a starting directory by that name the MV command complains, though, it does still remove the author-name-string from it's original location in the filename as desired.
find
command provide an-execdir
option?