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:
Can I use a similar methodology to what is found in the post above?
Thanks! jml
Yes, quite easily, with find.
find rootDir -name "myprefix_*"
This will give you a list of all files and folders in rootDir
that start with myprefix_
. From there, it's a short jump to a batch rename:
find rootDir -name "myprefix_*" | while read f
do
echo "Moving $f to ${f/myprefix_/}"
mv "$f" "${f/myprefix_/}"
done
EDIT: IFS
added per http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
EDIT 2: IFS
removed in favor of while read
.
EDIT 3: As bos points out, you may need to change while read f
to while read -d $'\n' f
if your version of Bash still doesn't like it.