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.

Is there a way to tell what encoding is used for the name and content of a file? Both GUI and terminal solutions (preferred) are fine. Thanks and regards!

share|improve this question

2 Answers 2

up vote 4 down vote accepted

You could try

chardet <<<filename

The chardet program can try to guess the encoding of the stream on stdin, and <<< is the mean by which bash use a string as stdin, the same as

echo filename | chardet

For a whole directory content you can use

ls dir | chardet

EDIT

I forgot about the content, but is almost the same:

chardet <filename

or

cat filename | chardet

or for all the files in dir

cat dir/* | chardet
share|improve this answer
    
Thanks! Nice to know chardet. I am trying to figure out the encodings of the names of the compressed files in a zip archive, but the output by chardet seems not correct. Please see my post here askubuntu.com/questions/48158/… . Thanks! –  Tim Jun 10 '11 at 22:57

If you mean mime-encoding you could try file --mime-encoding filename for the content of the file.

share|improve this answer
    
Thanks! How about the file name? –  Tim Jun 10 '11 at 21:22
    
I never put special chars in filenames. I remember there was some command which tries to detect the encoding from a string, then you can just pipe the filename through this... –  Marcel Jun 10 '11 at 21:26
    
Thanks! I was wondering what differences are between "mime-encoding" and "character encoding"? –  Tim Jul 9 '11 at 15:33

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.