Ubuntu view and batch modify file encoding method

  
                

We all know that the file encoding in Windows defaults to gbk or gb2312, but many users sometimes need to move the files under Windows to the Linux system, so there are often garbled characters after the transfer. What should I do? Next, Xiaobian will introduce you to Ubuntu to view and batch modify the file encoding method.

enca tools can use to view the file encoding.

Installation command under Ubuntu:

sudo apt-get install enca

enca view file

enca -L zh_CN file View file encoding

enca -L zh_CN -x UTF-8 file Change file encoding

enca -L zh_CN -x UTF-8 "file1" file2 Do not want to overwrite the original file

Here is a script, Change file encoding in batches:

#! /bin/bash

#Change the file encoding to UTF-8

#使用

#1. Name the file encoding.sh

#2 Chmod +x encoding.sh

#3. /set_encoding.sh

#4. Enter the directory name

#5. Enter whether to recursively change

#$1 indicates whether you want to recursively modify the file encoding

Function change_file_encoing(){

for file in $(ls -l

Copyright © Windows knowledge All Rights Reserved