find a file's encoding

See which character encoding a text file is in, and convert it to UTF-8.

  • text

Steps

  1. file -i file.txt

    the kind of file and its charset (macOS: file -I)

  2. iconv -f ISO-8859-1 -t UTF-8 in.txt > out.txt

    convert it to UTF-8

  3. iconv -l

    the encodings iconv knows

  4. uchardet file.txt

    a better guess, if uchardet is installed

Notes

  • No tool can be sure of an encoding: it is a guess from the bytes.

Commands used

  • file
  • iconv

Each has a page in lore: lore file opens it.