How to Convert Files to UTF-8 Encoding in Linux

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

10 Responses

  1. Manjeet says:

    Thanks for sharing it, Can you please suggest what should be done in case file size is huge, as the file size we are having this script is not working on resulted in dump file.

    • Aaron Kili says:


      How big is the file you are working with? The script should work with huge files.

      • Manjeet says:

        Hi Aaron,

        File is not that big, it is failing for number of records more than 700, and no of columns will be 5-7 and our file is having Latin America and Chinese data as well. We have done as below, Kindly suggest if we can discuss over google chat.

        Our Script 
        cd $SRCFILEDIR
        for f in *txt
        encoding=$(file -b --mime-encoding $f)
                if [ utf-8 != $encoding ] && [ us-ascii != $encoding ] && [ binary != $encoding ]; then
                        iconv -f $encoding -t utf-8 $f -o $f
                        echo $encoding

        We get below error :

        us-ascii -- converted successfully
        us-ascii -- converted successfully
        binary -- converted successfully
        ./ line 6:  1156 Bus error               (core dumped) iconv -f $encoding -t utf-8 $f -o $f
        ./ line 6:  1161 Bus error               (core dumped) iconv -f $encoding -t utf-8 $f -o $f
  2. Mahdi says:

    I do not know why we must follow many step, type commands, to do a simple convert in Linux? because in windows only default notepad can change file encoding easily. I can say i do more and more time in Linux to do simple works that i do in windows.

    So i do and read all solution in the INTERNET (Thanks Google!)
    but the best and easily solution for this problem answered in ask Ubuntu forum :

    It using the Microsoft Visual Studio Code text editor to fix a simple file encoding

  3. Alejandro says:

    Great! Thank you very much

  4. Linards says:

    This was a great help in converting a file originally saved with notepad using Baltic symbols (turns out it was encoded with ISO8859-13). Thank you for the valuable information!

  5. Claudio Pereira says:

    Thanks for sharing, it was useful for me.

Leave a Reply to Aaron Kili Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.