Anna's notepad

Replace all spaces with underscores in filenames using bash

I decided to add this to my online notepad because it's such a simple thing to want to do, but trying to look it up often returns excessively complex solutions (using Perl, for example). It's doable with one mv command.

This command will affect all the files in whichever folder you're currently in (inside bash).

for file in *; do mv "$file" `echo $file | tr ' ' '_'`; done

#bash shell