惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

Feel.name

Centos7安装sngrep – Feel.name DNS大全 – Feel.name Linux服务器密钥登陆方法 – Feel.name 升级到最新OpenSSH_9.3p1, OpenSSL 3.1.1 – Feel.name centos 7上创建sftp服务 – Feel.name linux清理缓存(cache) – Feel.name 通过yum来下载RPM包的方法 – Feel.name 年末守望新年期盼 – Feel.name message 日志里面的“Created slice User Slice of root.”日志去除方法 – Feel.name
Linux下转换文件编码 – Feel.name
Feel · 2024-05-07 · via Feel.name

Skip to content

有的时候查看文件格式的时候会发现有趣的事情

[root@feel ~]# file system.cfg
system.cfg: Non-ISO extended-ASCII text, with CRLF, NEL line terminators

with CRLF, NEL line terminators可以判断是windwos的文件

linux文本格式为:ASCII text

windows文本格式为:ASCII text,with CRLF line terminators

通过cat -v 文件名命令查看文本内容,行尾有^M符号

yum install dos2unix -y

dos2unix system.cfg

可以变更为ASCII text

通过enca判断文件编码

yum install enca

[root@feel ~]# enca –list languages
belarusian: CP1251 IBM866 ISO-8859-5 KOI8-UNI maccyr IBM855 KOI8-U
bulgarian: CP1251 ISO-8859-5 IBM855 maccyr ECMA-113
czech: ISO-8859-2 CP1250 IBM852 KEYBCS2 macce KOI-8_CS_2 CORK
estonian: ISO-8859-4 CP1257 IBM775 ISO-8859-13 macce baltic
croatian: CP1250 ISO-8859-2 IBM852 macce CORK
hungarian: ISO-8859-2 CP1250 IBM852 macce CORK
lithuanian: CP1257 ISO-8859-4 IBM775 ISO-8859-13 macce baltic
latvian: CP1257 ISO-8859-4 IBM775 ISO-8859-13 macce baltic
polish: ISO-8859-2 CP1250 IBM852 macce ISO-8859-13 ISO-8859-16 baltic CORK
russian: KOI8-R CP1251 ISO-8859-5 IBM866 maccyr
slovak: CP1250 ISO-8859-2 IBM852 KEYBCS2 macce KOI-8_CS_2 CORK
slovene: ISO-8859-2 CP1250 IBM852 macce CORK
ukrainian: CP1251 IBM855 ISO-8859-5 CP1125 KOI8-U maccyr
chinese: GBK BIG5 HZ
none:

[root@feel ~]# enca -L chinese system.cfg
Unrecognized encoding

enca会显示是编码

[root@feel ~]# enca -L czech system.cfg
Kamenicky encoding; KEYBCS2

iconv –list 查看iconv支持的编码

可以写个脚本一个一个测试编码

脚本如下

#!/bin/bash

iconv –list | sed ‘s/\/\/$//’ | sort > encodings.list
for a in cat encodings.list; do
printf “$a “
iconv -f $a -t UTF-8 system.cfg > /dev/null 2>&1 && echo “ok: $a” || echo “fail: $a”
done | tee result.txt

跑脚本后查看result.txt里的ok 就可以了。

这样就能转换好文件编码了。

iconv -f 源编码 -t UTF-8 转换前文件名 > 转换后文件名