Copy and Rename Multiple Files with Regular Expressions in bash
Here is a solution which use the find
command:
find . -name '20*' | while read oldname; do echo mv "$oldname" "${oldname/20/10}"; done
This command does not actually do your bidding, it only prints out what should be done. Review the output and if you are happy, remove the echo
command and run it for real.
Just wanna add to Explosion Pill's answer. On OS X though, you must say
mv "${file}" "${file_expression}"
Or the mv
command does not recognize it.
You just have a little bit of incorrect syntax is all:
for file in */20?????.*; do mv $file ${file/20/10}; done
- Remove quotes from the argument to
in
. Otherwise, the filename expansion does not occur. - The
$
in the substitution should go before the bracket