iconv – Converts the Encoding of the File

The iconv command is a Linux utility that converts the encoding of a file from one character set to another. It can be used to convert text files between different character sets, such as ASCII, Unicode, and ISO-8859. This command is useful when you need to work with files that have different character sets, especially when dealing with internationalization.


The iconv command is used to convert the encoding of a file. The basic syntax for using the command is as follows:

iconv [options] -f from-encoding -t to-encoding input-file > output-file

Here, from-encoding is the original encoding of the input file, and to-encoding is the desired encoding for the output file. The input file is specified with the -i option, and the output file is specified with the > operator.

For example, to convert a file from UTF-8 to ISO-8859-1 encoding, you would use the following command:

iconv -f UTF-8 -t ISO-8859-1 input.txt > output.txt

This command takes the file input.txt, which is encoded in UTF-8, and converts it to the ISO-8859-1 encoding, saving the output to output.txt.


The iconv command has several options that can be used to customize its behavior. The following table lists the available options:

Option Description
-f encoding Specifies the input encoding.
-t encoding Specifies the output encoding.
-c Ignores any invalid characters in the input file.
-s Suppresses any warnings that may be generated during the conversion process.
-o file Specifies the output file.
-l Lists all available encodings.

Troubleshooting Tips

One common issue when using the iconv command is encountering errors when converting files with non-standard characters. In such cases, you may need to manually specify the encoding of the input file using the -f option. Additionally, if the output file already exists, you may need to use the -o option to specify a new output file.


The iconv command is a powerful tool for converting the encoding of text files. It can be used to convert files between a wide variety of character sets, making it a valuable utility for internationalization and localization. However, it is important to be careful when using this command, as it can potentially cause data loss or corruption if used incorrectly. Always make sure to test your conversions thoroughly before using the output files in production.