Linux command
iconv 命令
文本
Uses pipes, overwrite, or deletion. Check paths and options first.
命令示例
Convert file
iconv -f UTF-8 -t ISO-8859-1 [input.txt] > [output.txt]
Convert file
iconv -f UTF-8 -t ASCII//TRANSLIT [input.txt] -o [output.txt]
List available encodings
iconv -l
Convert with transliteration
iconv -f UTF-8 -t ASCII//TRANSLIT [input.txt]
Convert ignoring errors
iconv -f UTF-8 -t ASCII//IGNORE [input.txt]
Convert from Windows codepage
iconv -f CP1252 -t UTF-8 [windows.txt]
Convert from stdin
cat [file.txt] | iconv -f UTF-8 -t UTF-16
说明
iconv converts text files from one character encoding to another. It reads input in the source encoding and writes output in the target encoding, handling the character mapping between different character sets. The tool supports hundreds of encodings including UTF-8, ISO-8859 family, Windows code pages, Asian encodings, and legacy formats. Special suffixes //TRANSLIT (approximate conversion) and //IGNORE (skip unconvertible) modify conversion behavior. iconv is essential for handling files from different systems, migrating legacy data, and ensuring proper text display across platforms with different default encodings.
参数
- -f _encoding_, --from-code= _encoding_
- Source encoding.
- -t _encoding_, --to-code= _encoding_
- Target encoding.
- -l, --list
- List available encodings.
- -o _file_, --output= _file_
- Output file.
- -c
- Silently discard unconvertible characters.
- -s, --silent
- Suppress warnings.
- --verbose
- Print progress information.
- //TRANSLIT
- Transliterate unconvertible characters.
- //IGNORE
- Skip unconvertible characters.
FAQ
What is the iconv command used for?
iconv converts text files from one character encoding to another. It reads input in the source encoding and writes output in the target encoding, handling the character mapping between different character sets. The tool supports hundreds of encodings including UTF-8, ISO-8859 family, Windows code pages, Asian encodings, and legacy formats. Special suffixes //TRANSLIT (approximate conversion) and //IGNORE (skip unconvertible) modify conversion behavior. iconv is essential for handling files from different systems, migrating legacy data, and ensuring proper text display across platforms with different default encodings.
How do I run a basic iconv example?
Run `iconv -f UTF-8 -t ISO-8859-1 [input.txt] > [output.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -f _encoding_, --from-code= _encoding_ do in iconv?
Source encoding.