Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So far I have:

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

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

1 Answer 1

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

 
discard

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.