4

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!

2 Answers 2

4

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
1
  • 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, 2011 at 22:57
2

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

3
  • Thanks! How about the file name?
    – Tim
    Jun 10, 2011 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, 2011 at 21:26
  • Thanks! I was wondering what differences are between "mime-encoding" and "character encoding"?
    – Tim
    Jul 9, 2011 at 15:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .