I am trying to rename all files containing _2_ to -2-
find ./ -depth -name "*_2_*" -exec /usr/bin/rename _2_ '-2-' {} \+
but I get the following error:
/usr/bin/rename: invalid option -- '2'
This is a common problem when dealing with filenames that have a leading -, because this is the same character used to indicate command line options.
A fairly common behavior is to interpret the argument -- to mean "end of options", so you can do something like:
find ./ -depth -name "*_2_*" -exec /usr/bin/rename -- _2_ '-2-' {} \+
I've tested this locally and that seems to Do The Right Thing on my system.