linux7更改字符集,CentOS7修改文件的字符集

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

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

7e1ae94f24cf785446096e4e08831c67.png

操作步骤:

1、查看系统字符集

[root@node1 ~]# cat /etc/locale.conf

LANG="en_US.UTF-8"

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

[root@node1 ~]# cat test.txt

feab2c1840e6d522be1349408477944d.png

3、查看文件字符集

[root@node1 ~]# file -i test.txt

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

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

[root@node1 ~]# iconv -f iso-8859-1 -t utf-8 -o test1.txt test.txt

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

[root@node1 ~]# cat test1.txt

c01ca66451fe9de54946aaa815e0496a.png

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

[root@node1 ~]# 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)

[root@node1 ~]# cat test2.txt

63ca1feed19863dc96ec6380e538321b.png

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

[root@node1 ~]# file -i test2.txt

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

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

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

使用iconv命令修改字符集:

[root@node1 ~]# 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命令查看字符集:

root@node1 ~]# 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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值