Find and replace string in directory names

findrename

I have a file structure that I had to recover and it contains :2f in the name

For example directory name anyname:2fmorename

I want to be able to change :2f to _ in all directories and sub directories.

I thinking something like

find . -name *:2f* -type d -execdir mv{} *_* \;

But I can not figure out for sure.

Best Answer

If you have the Perl rename installed you can do it with this:

find . -name '*:2f*' -type d -exec rename 's/:2f/_/g' {} \;

If you want to test it first then add an echo:

find . -name '*:2f*' -type d -exec echo rename 's/:2f/_/g' {} \;
Related Question