June 15, 2009 Archives

2009-06-15 01:05:27

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!

Posted by haui | Permanent Link | Categories: linux