Change a files character encoding standard using the ICONV command in Linux

Home > Search > Linux commands
  by

In this example, a .txt file was created in Windows Notepad, and the file contains the special character â.

 

When attempting to view this file using a Linux text editor, the â character may not be displayed. This problem occurs because the text editor or the Linux system may not use a character encoding standard that supports the â character.

 


LC_ALL

One solution to this problem is to update the LC_ALL variable in the /usr/bin/locale file to use a character encoding standard that supports the â character, such as UTF8.

LC_ALL=en_US.utf8

 

The Linux text editor now properly displays the â character.

 

However, setting the LC_ALL variable to use UTF8 may not be an ideal solution, because this would update the entire operating system to use UTF8. The iconv command can be used to update the file to use UTF8.

 


iconv

The iconv command with the -f or --from-code and -t or --to-code options can be used to convert a file from a certain character encoding standard to another character encoding standard. For example, to convert example.txt from ISO-8859-15 to UTF8, and to make a new file named newfile.txt.

[root@server1 ~]# iconv -f iso-8859-15 -t UTF-8 /home/user1/example.txt > /home/user1/newfile.txt

 

newfile.txt will properly display the â character.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments