probably the easiest solution, since you're using bash is to iterate over the list of files with a for
loop:
$ for i in *; do rename -n 's/Name1_/Name2_/' $i; done
you can also filter the files if needed by using any wildcard in the command, like *.log
.
There are other more convoluted ways to achieve this, especially if you need to do particular string manipulation of the file name, i.e. using awk
or find -exec
, but hopefully this could help you sort things out in a clear way.
Edited answer as suggested by @glglgl
a more comprehensive and detailed explanation of the above can be found on superuser:
https://superuser.com/questions/31464/looping-through-ls-results-in-bash-shell-script