How to rename files with spaces to use the underscore character instead .. or any other web friendly character.
I’ve just been handed a zip full of files, and want to host them, but they’ve all got nice pretty spaces in the file names. I *know* we can do that, it’s 2012 after all, but for the sake of keeping it “web safe” and catering to any possible user I’m going to rename them.
Linux already has a nice tool for bulk renaming called
So to turn space characters into underscores:
But, the fun part is the rename that ships with Archlinux is NOT the rename that ships with Debian/Ubuntu – The Debian/Ubuntu one can take regular expressions in the form of rename ‘s/old/new/g’ * but the Archlinux one can not – The Archlinux one only looks for the first instance of the expression ‘ ‘. You could just run the command a bunch of times, but there is (always) a better way:
Which installs as renamexm as not to conflict with the installed on.
From there, we can go back to the original plan of removing those darn spaces with a simple bit of regex
renamexm -s/\ /_/g *