Wednesday, 7 November 2007

The file and iconv commands

file and iconv are two simple but useful commands handy when dealing with files of different character encondings.

file <file path>


The file command makes a guess of what kind of file a file is. If you are lucky it may, for instance, help you to find out that a text file is encoded using UTF16, or ISO-8859-1, etc.

iconv -f <current encoding> -t <target encoding> <file path>

The iconv command is useful for converting between different character encodings. For instance, if you have noticed (with the help of the file command above) that a Unicode file is in UTF16, but you want in to be UTF8, you may use the iconv command:

iconv -f utf16 -t utf8 <file path>

(There are other, similar, commands, but for some reason iconv appears to be the only one that I can remember the name of.)

No comments: