Find and replace filename recursively in a directory

You can do it this way:

find . -name '123_*.txt' -type f -exec sh -c '
for f; do
    mv "$f" "${f%/*}/${f##*/123_}"
done' sh {} +

No pipes, no reads, no chance of breaking on malformed filenames, no non-standard tools or features.

Leave a Comment