for i in L*;
cd $i
find . -type f -name 'botrytis_cinerea_T12345.*' -exec rename 's/botrytis_cinerea_T12345/"$i"/g' {} \;

I get the error

find: missing argument to `-exec' rename: not enough arguments

Usage:  rename [options] expression replacement file...

Options:  -v, --verbose    explain what is being done  -s, --symlink   act on symlink target

 -h, --help     display this help and exit  -V, --version  output version information and exit

For more details see rename(1).

2 Answers 2


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 cding 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" {} \;

See also

  • 1
    Any comment on the cd in their code and how the loop is expected to not be able to handle more than one iteration, and what they could do about that?
    – Kusalananda
    Nov 6, 2019 at 16:47
  • @Kusalananda Good point. I'm paranoid about cding in scripts so I wrote a solution based on changing find instead.
    – trent
    Nov 6, 2019 at 17:10

The single quotes will stop expansion. And {} might need to be escaped Do this instead:

find . -type f -name 'botrytis_cinerea_T12345.*' -exec rename "s/botrytis_cinerea_T12345/$i/g" \{\} \;
  • I get the same error.
    – Fuyou Fu
    Nov 6, 2019 at 16:04
  • Sorry, I updated my answer, you actually need to escape the "{}" Nov 6, 2019 at 16:09
  • Note that their code is stepping down into a directory with cd, but that they never change back to the original directory. I would expect the code to eventually generate errors from cd too. Also, {} does not need to be escaped as it's not special to the shell (unless the user is using csh or tcsh).
    – Kusalananda
    Nov 6, 2019 at 16:16

Not the answer you're looking for? Browse other questions tagged .