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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like