Can anyone recommend a safe solution to recursively replace spaces with underscores in file and directory names starting from a given root directory? For example,
$ tree
.
|-- a dir
|   `-- file with spaces.txt
`-- b dir
    |-- another file with spaces.txt
    `-- yet another file with spaces.pdf
becomes
$ tree
.
|-- a_dir
|   `-- file_with_spaces.txt
`-- b_dir
    |-- another_file_with_spaces.txt
    `-- yet_another_file_with_spaces.pdf
Edit
Thanks for the answers; they all seem to work. I picked the one by Dennis as the main answer because it seems to me the simplest, even though it takes two steps.