iconv: convert text files between character encodings
Fix mojibake and convert GBK, Latin-1 or ISO-8859 files to UTF-8 on Linux with iconv.
Run iconv -f SOURCE_ENCODING -t UTF-8 FILE -o OUT to recode a file (use -l to list all supported encodings).
01Command
Command
$ iconv -f GBK -t UTF-8 input.txt -o output.txt02What it does
iconv converts the bytes of a file from one character set to another — the fix for files that show garbage in one editor and fine text in another. Common jobs include GB2312/GBK to UTF-8, Windows-1252/Latin-1 cleanup, and UTF-16 exports from Windows tools. Because it writes to stdout by default, -o (or shell redirection) names the converted file, and //TRANSLIT can approximate characters missing from the target set.
03Risk
!Warning: Converting in place with the same input and output name destroys the file if the declared source encoding is wrong — always write to a new file first.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- iconv(1) — Arch Linux manualEvidence: -f source encoding, -t target encoding, -o output file, -l lists supported encodings
- iconv(1) — Ubuntu manpageEvidence: Documents iconv conversion between encodings with --from-code and --to-code
Last verified: 2026-09-17 · Category: Files & Folders