Home·Terminal commands

iconv

Text processing

Usage

iconv -f [from] -t [to] [file]

Converts text from one character encoding to another; it stops at the first byte it cannot map unless you add -c, and it cannot guess the input encoding for you.

Common flags

FlagMeaning
-fThe encoding the input is in
-tThe encoding you want out
-lList every encoding name this build knows
-cDrop the characters that cannot be converted
//TRANSLITGNU: append to the target to swap unmappable letters for lookalikes

Examples

iconv -f EUC-KR -t UTF-8 old.csv > new.csv

Fixes a legacy Korean CSV.

iconv -f UTF-8 -t ASCII//TRANSLIT text.txt

Turns accented letters into plain ones (GNU).

iconv -l | grep -i 1252

Checks that an encoding name is spelled right.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does iconv do?

Converts text from one character encoding to another; it stops at the first byte it cannot map unless you add -c, and it cannot guess the input encoding for you.

Q. How do I type it?

iconv -f [from] -t [to] [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man iconv. This command sits under Text processing.

Related commands

man page: man iconv