Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert filenames from unicode to ascii

I have a bunch of music files on a NTFS partition mounted on linux that have filenames with unicode characters. I'm having trouble writing a script to rename the files so that all of the file names use only ASCII characters. I think that using the iconv command should work, but I'm having trouble escaping the characters for the 'mv' command.

EDIT: It doesn't matter if there isn't a direct translieration for the unicode chars. I guess that i'll just replace those with a "?" character.

like image 899
zedwarth Avatar asked Feb 26 '23 21:02

zedwarth


1 Answers

convmv is a good Perl script to convert file name encodings. But it can't handle characters that aren't in the destination encoding.

You can change any character not in ASCII to '?' using the rename utility distributed with Perl:

rename 's/[^ -~]/?/g' *

Unfortunately this replaces multi-byte characters with multiple '?'s. Depending on the Unicode encoding that is used and the characters involved changing the regex may help, e.g.

rename 's/[^ -~]{2}/?/g' *

for 2-byte characters.

like image 119
Florian Diesch Avatar answered Mar 01 '23 23:03

Florian Diesch