Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So far I have:

for file in *\_*
do file_clean="${file//_/ }"
mv --verbose "$file" "$file_clean"

However, it only renames files in the root directory of the folder. How do I make it rename the files with underscores to spaces recursively on all of the files and folders within that directory?

share|improve this question

Consider using the find command (see man find). That will go through all subdirectories and can run a command file on each file name using the -exec {} option.

share|improve this answer
Thanks. I used "find /this/ismydirectory/ -depth -name "_" -execdir rename 's/_/ /g' "{}" \;" to rename my directories. Seems to be working perfectly. – Adam Lee Kincaid Jan 17 '13 at 23:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.