Recursive Directory Renaming

Recursive Directory Renaming

I need to recursively append the same suffix to all sub-directory names in a directory. What is a simple and safe way to do this?

1 Answer

Using find and rename:

find . -depth -type d -not -name '.' -exec rename -n 's/(.*)/$1_foo/' {} +

This will add suffix _foo to all directories recursively, -n will show the names of the directories that will be changed.

If you are satisfied with the names you can remove the -n option to let the action take place:

find . -depth -type d -not -name '.' -exec rename 's/(.*)/$1_foo/' {} +
8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.