I got help regarding the following question:
batch rename files with ids intact
It’s a great example of how to rename specific files in a group, but I am wondering if there is a similar script I could use to do the following:
- I have a group of nested folders and files within a root directory that contain [myprefix_foldername] and [myprefix_filename.ext]
- I would like to rename all of the folders and files to [foldername] and [filename.ext]
Can I use a similar methodology to what is found in the post above?
Thanks!
jml
Yes, quite easily, with find.
This will give you a list of all files and folders in
rootDirthat start withmyprefix_. From there, it’s a short jump to a batch rename:EDIT:
IFSadded per http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.htmlEDIT 2:
IFSremoved in favor ofwhile read.EDIT 3: As bos points out, you may need to change
while read ftowhile read -d $'\n' fif your version of Bash still doesn’t like it.