{"id":210655,"date":"2023-12-22T07:24:19","date_gmt":"2023-12-21T23:24:19","guid":{"rendered":"https:\/\/www.idc.net\/help\/210655\/"},"modified":"2023-12-22T07:24:19","modified_gmt":"2023-12-21T23:24:19","slug":"linux-%e5%91%bd%e4%bb%a4%ef%bc%9aiconv-%e5%b0%86%e7%bb%99%e5%ae%9a%e6%96%87%e4%bb%b6%e4%bb%8e%e4%b8%80%e7%a7%8d%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e4%b8%ba%e5%8f%a6%e4%b8%80%e7%a7%8d%e7%bc%96","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/210655\/","title":{"rendered":"Linux \u547d\u4ee4\uff1aiconv &#8211; \u5c06\u7ed9\u5b9a\u6587\u4ef6\u4ece\u4e00\u79cd\u7f16\u7801\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7f16\u7801"},"content":{"rendered":"<p><title id=\"linux-%e5%91%bd%e4%bb%a4%ef%bc%9aiconv-%e5%b0%86%e7%bb%99%e5%ae%9a%e6%96%87%e4%bb%b6%e4%bb%8e%e4%b8%80%e7%a7%8d%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e4%b8%ba%e5%8f%a6%e4%b8%80%e7%a7%8d%e7%bc%96-TswYvbohof\">Linux \u547d\u4ee4\uff1aiconv - \u5c06\u7ed9\u5b9a\u6587\u4ef6\u4ece\u4e00\u79cd\u7f16\u7801\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7f16\u7801<\/title><\/p>\n<h1 id=\"linux-%e5%91%bd%e4%bb%a4%ef%bc%9aiconv-%e5%b0%86%e7%bb%99%e5%ae%9a%e6%96%87%e4%bb%b6%e4%bb%8e%e4%b8%80%e7%a7%8d%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e4%b8%ba%e5%8f%a6%e4%b8%80%e7%a7%8d%e7%bc%96-TswYvbohof\">Linux \u547d\u4ee4\uff1aiconv - \u5c06\u7ed9\u5b9a\u6587\u4ef6\u4ece\u4e00\u79cd\u7f16\u7801\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7f16\u7801<\/h1>\n<p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0ciconv\u547d\u4ee4\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5c06\u7ed9\u5b9a\u6587\u4ef6\u4ece\u4e00\u79cd\u7f16\u7801\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7f16\u7801\u3002\u65e0\u8bba\u662f\u5728\u5904\u7406\u6587\u672c\u6587\u4ef6\u8fd8\u662f\u5728\u5904\u7406\u7f51\u7edc\u6570\u636e\u65f6\uff0ciconv\u547d\u4ee4\u90fd\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8f7b\u677e\u5730\u8fdb\u884c\u7f16\u7801\u8f6c\u6362\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%85iconv-TswYvbohof\">\u5b89\u88c5iconv<\/h2>\n<p>\u5728\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u4e2d\uff0ciconv\u547d\u4ee4\u5df2\u7ecf\u9884\u88c5\u4e86\u3002\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u6ca1\u6709\u5b89\u88c5iconv\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<pre><code>sudo apt-get install glibc-iconv\n<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8iconv%e5%91%bd%e4%bb%a4-TswYvbohof\">\u4f7f\u7528iconv\u547d\u4ee4<\/h2>\n<p>iconv\u547d\u4ee4\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>iconv -f \u6e90\u7f16\u7801 -t \u76ee\u6807\u7f16\u7801 \u8f93\u5165\u6587\u4ef6 &gt; \u8f93\u51fa\u6587\u4ef6\n<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>-f<\/code>\u53c2\u6570\u6307\u5b9a\u8f93\u5165\u6587\u4ef6\u7684\u7f16\u7801\uff0c<code>-t<\/code>\u53c2\u6570\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6\u7684\u7f16\u7801\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>-l<\/code>\u53c2\u6570\u6765\u5217\u51fa\u6240\u6709\u652f\u6301\u7684\u7f16\u7801\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684iconv\u547d\u4ee4\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e5%b0%86utf-8%e7%bc%96%e7%a0%81%e7%9a%84%e6%96%87%e4%bb%b6%e8%bd%ac%e6%8d%a2%e4%b8%bagbk%e7%bc%96%e7%a0%81-TswYvbohof\">\u5c06UTF-8\u7f16\u7801\u7684\u6587\u4ef6\u8f6c\u6362\u4e3aGBK\u7f16\u7801<\/h3>\n<pre><code>iconv -f UTF-8 -t GBK input.txt &gt; output.txt\n<\/code><\/pre>\n<h3 id=\"%e5%b0%86gbk%e7%bc%96%e7%a0%81%e7%9a%84%e6%96%87%e4%bb%b6%e8%bd%ac%e6%8d%a2%e4%b8%bautf-8%e7%bc%96%e7%a0%81-TswYvbohof\">\u5c06GBK\u7f16\u7801\u7684\u6587\u4ef6\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801<\/h3>\n<pre><code>iconv -f GBK -t UTF-8 input.txt &gt; output.txt\n<\/code><\/pre>\n<h3 id=\"%e5%b0%86iso-8859-1%e7%bc%96%e7%a0%81%e7%9a%84%e6%96%87%e4%bb%b6%e8%bd%ac%e6%8d%a2%e4%b8%bautf-8%e7%bc%96%e7%a0%81-TswYvbohof\">\u5c06ISO-8859-1\u7f16\u7801\u7684\u6587\u4ef6\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801<\/h3>\n<pre><code>iconv -f ISO-8859-1 -t UTF-8 input.txt &gt; output.txt\n<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8iconv%e5%a4%84%e7%90%86%e6%96%87%e6%9c%ac%e6%96%87%e4%bb%b6-TswYvbohof\">\u4f7f\u7528iconv\u5904\u7406\u6587\u672c\u6587\u4ef6<\/h2>\n<p>iconv\u547d\u4ee4\u4e0d\u4ec5\u53ef\u4ee5\u5904\u7406\u666e\u901a\u6587\u672c\u6587\u4ef6\uff0c\u8fd8\u53ef\u4ee5\u5904\u7406CSV\u6587\u4ef6\u3001XML\u6587\u4ef6\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e5%b0%86csv%e6%96%87%e4%bb%b6%e4%bb%8egbk%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e4%b8%bautf-8%e7%bc%96%e7%a0%81-TswYvbohof\">\u5c06CSV\u6587\u4ef6\u4eceGBK\u7f16\u7801\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801<\/h3>\n<pre><code>iconv -f GBK -t UTF-8 input.csv &gt; output.csv\n<\/code><\/pre>\n<h3 id=\"%e5%b0%86xml%e6%96%87%e4%bb%b6%e4%bb%8eutf-16%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e4%b8%bautf-8%e7%bc%96%e7%a0%81-TswYvbohof\">\u5c06XML\u6587\u4ef6\u4eceUTF-16\u7f16\u7801\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801<\/h3>\n<pre><code>iconv -f UTF-16 -t UTF-8 input.xml &gt; output.xml\n<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8iconv%e5%a4%84%e7%90%86%e7%bd%91%e7%bb%9c%e6%95%b0%e6%8d%ae-TswYvbohof\">\u4f7f\u7528iconv\u5904\u7406\u7f51\u7edc\u6570\u636e<\/h2>\n<p>\u5728\u5904\u7406\u7f51\u7edc\u6570\u636e\u65f6\uff0ciconv\u547d\u4ee4\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u89e3\u51b3\u7f16\u7801\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e5%b0%86http%e5%93%8d%e5%ba%94%e4%bb%8eiso-8859-1%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e4%b8%bautf-8%e7%bc%96%e7%a0%81-TswYvbohof\">\u5c06HTTP\u54cd\u5e94\u4eceISO-8859-1\u7f16\u7801\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801<\/h3>\n<pre><code>curl http:\/\/example.com | iconv -f ISO-8859-1 -t UTF-8\n<\/code><\/pre>\n<h3 id=\"%e5%b0%86%e6%96%87%e6%9c%ac%e6%95%b0%e6%8d%ae%e4%bb%8egbk%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e4%b8%bautf-8%e7%bc%96%e7%a0%81-TswYvbohof\">\u5c06\u6587\u672c\u6570\u636e\u4eceGBK\u7f16\u7801\u8f6c\u6362\u4e3aUTF-8\u7f16\u7801<\/h3>\n<pre><code>echo \"\u4f60\u597d\uff0c\u4e16\u754c\" | iconv -f GBK -t UTF-8\n<\/code><\/pre>\n<h2 id=\"%e6%80%bb%e7%bb%93-TswYvbohof\">\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7iconv\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u7ed9\u5b9a\u6587\u4ef6\u4ece\u4e00\u79cd\u7f16\u7801\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7f16\u7801\u3002\u65e0\u8bba\u662f\u5904\u7406\u6587\u672c\u6587\u4ef6\u8fd8\u662f\u5904\u7406\u7f51\u7edc\u6570\u636e\uff0ciconv\u547d\u4ee4\u90fd\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5bfb\u627e\u4e00\u4e2a\u53ef\u9760\u7684\u4e91\u8ba1\u7b97\u670d\u52a1\u63d0\u4f9b\u5546\uff0c\u540e\u6d6a\u4e91\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u4ed6\u4eec\u63d0\u4f9b\u9999\u6e2f\u670d\u52a1\u5668\u3001\u7f8e\u56fd\u670d\u52a1\u5668\u548c\u4e91\u670d\u52a1\u5668\u7b49\u591a\u79cd\u4ea7\u54c1\u3002\u4f60\u53ef\u4ee5\u5728<a href=\"https:\/\/idc.net\">\u540e\u6d6a\u4e91\u5b98\u7f51<\/a>\u4e86\u89e3\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux \u547d\u4ee4\uff1aiconv - \u5c06\u7ed9\u5b9a\u6587\u4ef6\u4ece\u4e00\u79cd\u7f16\u7801\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7f16\u7801 Linux \u547d\u4ee4\uff1aiconv - \u5c06\u7ed9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-210655","post","type-post","status-publish","format-standard","hentry","category-centos"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/210655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=210655"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/210655\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=210655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=210655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=210655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}