Haui's bytes

news, diary, journal, whatever

rename

One of the most annoying things about copying files from Windows systems on your local linux box are the strange filenames, Windows users consider to be state-of-the-art. Most of these names seem to consist solely of uppercase and special characters and of course lots of whitespaces... However, as we’re running linux, the solution is just one simple command away: prename (rename on some systems), which is included in the standard Perl distribution, makes it possible:

#just pretend....
rename -n 's#\s+#_#g ;y#A-Z#a-z#;s#[^a-z0-9_\-.]#_#g;s#_+#_#g' *

#"sanitize" all filenames in the current directory if the output
#from above is ok
rename 's#\s+#_#g ;y#A-Z#a-z#;s#[^a-z0-9_\-.]#_#g;s#_+#_#g' *

BTW: This won’t work out-of-the-box with find’s exec-option!