5

Linux下utf-8 BOM 文件的检查与删除

 3 years ago
source link: https://www.liurongxing.com/check-file-utf-8-bom-and-delete-on-linux.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux下utf-8 BOM 文件的检查与删除

作者: JavasBoy 分类: Bash, Perl, Vim 发布时间: 2019-01-21 08:00 ė 110,729 views 6 3条评论

当源程序是 gbk 格式,你转换为 utf8 的时候,很多情况是头部会出现 bom,如果是 php 代码,这样会出现很多意想不到的事情,那怎么办呢,你可以用 linux 命令来查找,然后对文件的 bom 进行删除。

grep -r $'\xef\xbb\xbf' * |grep .php

bom:UTF-8签名(UTF-8 signature)也叫做BOM(Byte Order Mark)

查询BOM:

:set bomb?

用 vim 去掉 utf-8 BOM

:set nobomb

保留 utf-8 BOM

:set bomb

vim 转换文件为 unix 格式

:set ff=unix

使用 grep 查找带 bom 的文件,并使用 perl 去掉 bom 头

grep -rl $'\xEF\xBB\xBF' . | xargs perl -i -pe 's{\xEF\xBB\xBF}{}'

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK