Alexey Korotkov
Alexey Korotkov

Reputation: 13

Find with multiple rename

I need to rename several million files with multiple patterns. Some filenames have a few characters that i want to replace. In order not to scan all files multiple times I want to do all the replacements at once.

I tried these scripts:

find . -type f -name '*\.jpg' -exec rename 's/%c3%a0/\xc3\xa0/g' {} \; -exec rename 's/%c3%a9/\xc3\xa9/g' {} \; -exec rename 's/%c3%aa/\xc3\xaa/g' {} \;

find . -type f -name '*\.jpg' -exec rename 's/%c3%a0/\xc3\xa0/g' | -exec rename 's/%c3%a9/\xc3\xa9/g' | -exec rename 's/%c3%aa/\xc3\xaa/g'

These scripts replace only one character.

Help pls.

Upvotes: 1

Views: 60

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 208052

I think the problem is that your first rename renames the file, so when you exec your second rename on the same file, it has already gone because it has been renamed by the first one!

I think you will get on much better doing all the substitutions in one go, it will also save executing rename multiple times per file:

find ... -exec rename 's/a/b/g; s/c/d/g; s/e/f/g' {} \;

Upvotes: 2

Related Questions