1

How can I replace a string in all my folder names in one directory. For example if I have these folders

hellojoe hellomary hellosusan

I want to change these to

worldjoe worldmary worldsusan

fractal5
  • 2,034
  • 4
  • 29
  • 50
  • Are you trying to avoid changing the names of regular files? – William Pursell Apr 15 '20 at 15:22
  • Yes I would like to change the folder names only, without touching the files. In my case, that's not a concern, since there are no files in that folder, so my provided answer works. But being more explicit would make a better answer of course. – fractal5 Apr 15 '20 at 18:16
  • 1
    In the answer you've given, just add `-type d` to restrict to directories. – William Pursell Apr 15 '20 at 19:56

1 Answers1

2

Using this command works

find . -name 'hello*' -exec bash -c 'mv "$1" "${1/hello/world}"' -- {} \;
fractal5
  • 2,034
  • 4
  • 29
  • 50