There are two common rename
commands that have different syntaxes. You're using a script written for the version that accepts a Perl expression:
rename s/expression/replacement/g file...
But the one you have installed is the one that accepts both a regex and replacement string, as the error message you saw suggests:
rename [options] expression replacement file...
(Count yourself lucky, or smart, that you used \;
instead of +
.) You can fix this by adjusting your find
command:
find . -type f -name 'botrytis_cinerea_T12345.*' -exec rename botrytis_cinerea_T12345 "$i" {} \;
As Kusalananda pointed out in the comments, you're also cd
ing inside the loop, but never going back to the original directory, so each iteration after the first, you repeatedly attempt to cd
to a directory that doesn't exist. You might try to fix this by doing another cd
after find
, but I'd probably try to avoid that by adjusting the find
itself:
for i in L*; do
find "$i" -type f -name 'botrytis_cinerea_T12345.*' -exec rename botrytis_cinerea_T12345 "$i" {} \;
done
See also
rename
. Possible duplicate of Why is the rename utility on Debian/Ubuntu different than the one on other distributions, like CentOS?