天天看點

linux7更改字元集,CentOS7修改檔案的字元集

CentOS7修改文件的字符集命令:

iconv -f gbk -t utf-8 -o test2.txt test.txt

linux7更改字元集,CentOS7修改檔案的字元集

操作步骤:

1、查看系统字符集

[[email protected] ~]# cat /etc/locale.conf

2、查看文件内容(这个文件是我在windows上创建的txt文件)

[[email protected] ~]# cat test.txt

linux7更改字元集,CentOS7修改檔案的字元集

3、查看文件字符集

[[email protected] ~]# file -i test.txt

test.txt: text/plain; charset=iso-8859-1

4、修改字符集(按照上面获取到的字符集格式iso-8859-1进行修改)

[r[email protected] ~]# iconv -f iso-8859-1 -t utf-8 -o test1.txt test.txt

5、查看修改过字符集的文件test1.txt(iso-8859-1)

[[email protected] ~]# cat test1.txt

linux7更改字元集,CentOS7修改檔案的字元集

6、查看test1.txt文件字符集

[[email protected] ~]# file -i test1.txt

test1.txt: text/plain; charset=utf-8

7、修改字符集(因为我知道这个文件是在windows上创建的txt文件,索性就尝试用gbk转换)

iconv -f gbk -t utf-8 -o test2.txt test.txt

8、查看修改过字符集的文件test2.txt(gbk)

[[email protected] ~]# cat test2.txt

linux7更改字元集,CentOS7修改檔案的字元集

9、查看test2.txt文件字符集

[[email protected] ~]# file -i test2.txt

test2.txt: text/plain; charset=utf-8

10、至于为什么按照gbk的格式修改正常,而使用iso-8859-1的格式修改有问题,我也有疑问!

修改文件的字符集详细命令请看下面:

使用iconv命令修改字符集:

[[email protected] ~]# iconv --help

用法: iconv [选项...] [文件...]

转换给定文件的编码。

输入/输出格式规范:

-f, --from-code=名称 原始文本编码

-t, --to-code=名称 输出编码

信息:

-l, --list 列举所有已知的字符集

输出控制:

-c 从输出中忽略无效的字符

-o, --output=FILE 输出文件

-s, --silent 关闭警告

--verbose 打印进度信息

-?, --help 给出该系统求助列表

--usage 给出简要的用法信息

-V, --version 打印程序版本号

长选项的强制或可选参数对对应的短选项也是强制或可选的。

For bug reporting instructions, please see:

.

使用file命令查看字符集:

[email protected] ~]# file --help

Usage: file [OPTION...] [FILE...]

Determine type of FILEs.

--help display this help and exit

-v, --version output version information and exit

-m, --magic-file LIST use LIST as a colon-separated list of magic

number files

-z, --uncompress try to look inside compressed files

-b, --brief do not prepend filenames to output lines

-c, --checking-printout print the parsed form of the magic file, use in

conjunction with -m to debug a new magic file

before installing it

-e, --exclude TEST exclude TEST from the list of test to be

performed for file. Valid tests are:

ascii, apptype, compress, elf, soft, tar, tokens, troff

-f, --files-from FILE read the filenames to be examined from FILE

-F, --separator STRING use string as separator instead of `:'

-i, --mime output MIME type strings (--mime-type and

--mime-encoding)

--apple output the Apple CREATOR/TYPE

--mime-type output the MIME type

--mime-encoding output the MIME encoding

-k, --keep-going don't stop at the first match

-l, --list list magic strength

-L, --dereference follow symlinks (default)

-h, --no-dereference don't follow symlinks

-n, --no-buffer do not buffer output

-N, --no-pad do not pad output

-0, --print0 terminate filenames with ASCII NUL

-p, --preserve-date preserve access times on files

-r, --raw don't translate unprintable chars to \ooo

-s, --special-files treat special (block/char devices) files as

ordinary ones

-C, --compile compile file specified by -m

-d, --debug print debugging messages

Report bugs to http://bugs.gw.com/