Home > Software engineering >  How to find and rename a batch of files in linux
How to find and rename a batch of files in linux

Time:09-09

when using the following command:

find foo/bar -type f -name '*.txt' -execdir sh -c 'mv "$0" "new_prefix_${0}"' {}\;

I get the following error: mv: cannot move './abc.txt' to 'new_prefix_./abc.txt': No such file or directory

The './' is the problem, how can I avoid this?

CodePudding user response:

find foo/bar -type f -name '*.txt' -execdir sh -c 'mv "$0" "new_prefix_$(basename "$0")"' {} \;
  • Related