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
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
-
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!– TimJun 10, 2011 at 22:57
If you mean mime-encoding you could try
file --mime-encoding filename
for the content of the file.
-
-
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...– MarcelJun 10, 2011 at 21:26
-
Thanks! I was wondering what differences are between "mime-encoding" and "character encoding"?– TimJul 9, 2011 at 15:33