Convert files uploaded to Linux in GBK encoding to UTF-8 encoding

Convert files uploaded to Linux in GBK encoding to UTF-8 encoding

To convert a file uploaded to Linux in GBK encoding to UTF-8 encoding, you can follow the steps below

1. First, make sure your Linux system has the convmv tool installed. If it is not installed, you can use the following command to install it

yum install -y convmv

2. Then, use the convmv command to convert the file from GBK to UTF-8 encoding. Assuming that you have uploaded the file to a certain directory of the Linux system, you can use the following command to convert it

convmv -f gbk -t utf8 /path/to/file
请将/path/to/file替换为你上传的文件的路径。

If you want to batch convert all files in a directory, you can use the following command:

find /path/to/directory -type f -exec convmv -f gbk -t utf8 {
    
    } +

Please replace /path/to/directory with the directory path where you uploaded the file.

In this way, you can convert files uploaded to Linux in GBK encoding to UTF-8 encoding.

3. If there is a "No changes to your files done" prompt when using the convmv command, it means that convmv is running in test mode and does not actually rename the file. To actually rename files, you can use the --notest option. The following are specific command examples:

convmv -f gbk -t utf8 --notest /path/to/file
Or do a batch conversion of an entire directory
find /path/to/directory -type f -exec convmv -f gbk -t utf8 --notest {} +

4. If you don’t want to worry about how to use the above commands, just use the following

one-off:将目录/data的所有文件和文件夹进行处理:

#将目录下的所有文件(递归处理)由GBK转换成UTF8
find /data -type f -exec convmv -f gbk -t utf8 --notest {
    
    } +

#将目录下的所有文件夹(递归处理)由GBK转换成UTF8
find /data -type d -exec convmv -f gbk -t utf8 --notest {
    
    } +

Guess you like

Origin blog.csdn.net/jxlhljh/article/details/131823390