Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

i.e. i have a file called Porträt.pdf.

But the filename was created with a charsets which isn't properly shown in ubuntu like the following example.

enter image description here

What would be the best practice to rename such chars in filenames, when you have several filenames and you can't use this special char because of it's coding in terminal commands?

share|improve this question

3 Answers 3

In theory it can be tricky to know the character encoding used by the files, but in most cases the error comes from windows systems and programs still using just Latin1 instead of UTF-8. Run convmv -f cp850 -t utf-8 * without quotes in the folder with the broken files and have a try.

(You need convmv package installed)

share|improve this answer

I guess that modern OSes often chooses UTF-8 for encoding file names. In this sense it's not a problem to have non-US characters in the file names. What you have experienced is probably the result of a file name which was created with non-UTF-8 encoding. It's quite hard to tell what you can do with that, it's also depends what you'd like. If you need the correct file name (for example "Porträt.pdf") you need to know the encoding of the original file name first, then you can convert it/them. It's not so easy to "guess" only since there are huge amount of very different encodings.

share|improve this answer
    
seems to be a bit tricky. there are tools like iconv convmv to coonvert filenames from one encoding to another. But here it's best to know the origin encoding. One way could be convmv the filename to utf8 and then work on to rename with a tool like pyRenamer since it offers the option to copy paste the certain char and create a rule to replace it. but i wouldn't call this best practice. at all a big downside is that there seems no very reliable non error prone practice to determine the encoding of the original file. –  NES Feb 11 '11 at 15:40
1  
Well basically I wanted to tell this with my answer. "Best practice" is hard to define anyway in a case like this, when you lack information: the character encoding. What I can imagine: if you have those files from "same place" you can at least assume that the character encoding is the same. I would try a directory listing into a file and check the result of some run of iconv (for example) with different encoding are assumed. Still, it's quite a "try it ..." algorithm, and I have the idea that you can't find a very accurate, scientific-class solution for this problem ... :( –  LGB Feb 11 '11 at 21:12

If you just want to get rid of some characters, you could try this:

rename "s/[^A-Za-z0-9-_]/_/g"

That would replace every character that is not just char, number or dash with an underscore. Run with the -n option to see what is happening in a dry-run.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.