I want to rename files and directories. Let's suppose that I want to convert every ä
to a
, and I have Järjestelmä/Säätimet
. So I say something like find -exec rename 's/ä/a/g'
. Now find
will convert Järjestelmä
to Jarjestelma
and then complain that it did not found Järjestelmä
anymore.
If I could convert the order of exec
-commands to run it would solve this. Is it possible? If not, what is the right way to do this?
This is not a big problem, as I can run the command again until it makes no changes. Anyways this irritates me.
Best Answer
Use
find
's-depth
option, from the man page:That way it will process
Säätimet
beforeJärjestelmä
and will not complain about not being able to descend intoJärjestelmä
because you just renamed it.To prevent
rename
from handling the whole path use-execdir
present in a fewfind
implementations like BSDs and GNU (which changes to the directory and hands just the final part to the command argument{}
(with a./
prefix with some implementations)):gives: