{"id":51823,"date":"2024-12-03T17:38:05","date_gmt":"2024-12-03T09:38:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/51823\/"},"modified":"2024-12-03T17:38:05","modified_gmt":"2024-12-03T09:38:05","slug":"%e5%9c%a8linux%e7%b3%bb%e7%bb%9f%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bd%ac%e6%8d%a2%e6%96%87%e4%bb%b6%e7%9a%84%e7%bc%96%e7%a0%81%e6%a0%bc%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/51823\/","title":{"rendered":"\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u8f6c\u6362\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u8f6c\u6362\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f<\/h1>\n<p>\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u8f6c\u6362\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f\u300b<\/span>\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~<\/p>\n<ol>\n<li>\n<p>\u67e5\u770b\u6587\u4ef6\u7684\u7f16\u7801\\<\/p>\n<\/li>\n<\/ol>\n<pre>file<\/pre>\n<p>\u4f7f\u7528 file \u547d\u4ee4\uff0c\u5e76\u6dfb\u52a0-i\u6216\u2013mime\u53c2\u6570\u6765\u67e5\u770b\u4e00\u4e2a\u6587\u4ef6\u7684\u5b57\u7b26\u7f16\u7801\u3002<\/p>\n<ol>\n<li>\n<p>\u7f16\u7801\u8f6c\u6362\u5de5\u5177iconv<\/p>\n<\/li>\n<\/ol>\n<pre>iconv&nbsp;options&nbsp;-f&nbsp;from-encoding&nbsp;-t&nbsp;to-encoding&nbsp;inputfile(s)<\/pre>\n<p>-f\u6216\u2013from-code\u8868\u660e\u4e86\u8f93\u5165\u7f16\u7801\uff0c\u800c-t\u6216\u2013to-encoding\u6307\u5b9a\u4e86\u8f93\u51fa\u7f16\u7801\u3002<\/p>\n<ol>\n<li>\n<p>\u5217\u51fa\u6240\u6709\u652f\u6301\u7684\u7f16\u7801\u5b57\u7b26\u96c6<\/p>\n<\/li>\n<\/ol>\n<pre>iconv<\/pre>\n<ol>\n<li>\n<p>\u6587\u4ef6\u7f16\u7801\u8f6c\u6362\u7684\u4f8b\u5b50<\/p>\n<\/li>\n<\/ol>\n<pre>iconv<\/pre>\n<p>\u5c06\u6587\u4ef6\u4ece ISO-8859-1 \u7f16\u7801\u8f6c\u6362\u4e3a UTF-8 \u7f16\u7801\u3002<\/p>\n<p>\u5982\u679c\u8f93\u51fa\u7f16\u7801\u540e\u9762\u6dfb\u52a0\u4e86\/\/IGNORE\u5b57\u7b26\u4e32\uff0c\u90a3\u4e9b\u4e0d\u80fd\u88ab\u8f6c\u6362\u7684\u5b57\u7b26\u5c06\u4e0d\u4f1a\u88ab\u8f6c\u6362\uff0c\u5e76\u4e14\u5728\u8f6c\u6362\u540e\uff0c\u7a0b\u5e8f\u4f1a\u663e\u793a\u4e00\u6761\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<p>\u5982\u679c\u5b57\u7b26\u4e32\/\/TRANSLIT\u88ab\u6dfb\u52a0\u5230\u4e86\u4e0a\u9762\u4f8b\u5b50\u4e2d\u7684\u8f93\u51fa\u7f16\u7801\u4e4b\u540e (UTF-8\/\/TRANSLIT)\uff0c\u5f85\u8f6c\u6362\u7684\u5b57\u7b26\u4f1a\u5c3d\u91cf\u91c7\u7528\u5f62\u8bd1\u539f\u5219\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u67d0\u4e2a\u5b57\u7b26\u5728\u8f93\u51fa\u7f16\u7801\u65b9\u6848\u4e2d\u4e0d\u80fd\u88ab\u8868\u793a\u7684\u8bdd\uff0c\u5b83\u5c06\u4f1a\u88ab\u66ff\u6362\u4e3a\u4e00\u4e2a\u5f62\u72b6\u6bd4\u8f83\u76f8\u4f3c\u7684\u5b57\u7b26\u3002<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e0d\u5728\u8f93\u51fa\u7f16\u7801\u4e2d\uff0c\u800c\u4e14\u4e0d\u80fd\u88ab\u5f62\u8bd1\uff0c\u5b83\u5c06\u4f1a\u5728\u8f93\u51fa\u6587\u4ef6\u4e2d\u88ab\u4e00\u4e2a\u95ee\u53f7\u6807\u8bb0?\u4ee3\u66ff\u3002<\/p>\n<ol>\n<li>\n<p>\u5c06\u591a\u4e2a\u6587\u4ef6\u8f6c\u6362\u4e3a UTF-8 \u7f16\u7801<br \/>\u53ef\u4ee5\u5229\u7528shell\u811a\u672c<\/p>\n<\/li>\n<\/ol>\n<pre>#!\/bin\/bash\n###&nbsp;\u5c06&nbsp;values_here&nbsp;\u66ff\u6362\u4e3a\u8f93\u5165\u7f16\u7801\nFROM_ENCODING=\"value_here\"\n###&nbsp;\u8f93\u51fa\u7f16\u7801&nbsp;(UTF-8)\nTO_ENCODING=\"UTF-8\"\n###&nbsp;\u8f6c\u6362\u547d\u4ee4\nCONVERT=\"&nbsp;iconv&nbsp;&nbsp;-f&nbsp;&nbsp;&nbsp;$FROM_ENCODING&nbsp;&nbsp;-t&nbsp;&nbsp;&nbsp;$TO_ENCODING\"\n###&nbsp;\u4f7f\u7528\u5faa\u73af\u8f6c\u6362\u591a\u4e2a\u6587\u4ef6\nfor&nbsp;&nbsp;file&nbsp;&nbsp;in&nbsp;&nbsp;*.txt;&nbsp;do\n$CONVERT&nbsp;&nbsp;&nbsp;\"$file\"&nbsp;&nbsp;&nbsp;-o&nbsp;&nbsp;\"${file%.txt}.utf8.converted\"\ndone\nexit<\/pre>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u8f6c\u6362\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u8f6c\u6362\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f \u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300a\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u8f6c\u6362\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f\u300b\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~ \u67e5\u770b\u6587\u4ef6\u7684\u7f16\u7801\\ file \u4f7f\u7528 file \u547d\u4ee4\uff0c\u5e76\u6dfb\u52a0-i\u6216\u2013mime\u53c2\u6570\u6765\u67e5\u770b\u4e00\u4e2a\u6587\u4ef6\u7684\u5b57\u7b26\u7f16\u7801\u3002 \u7f16\u7801\u8f6c\u6362\u5de5\u5177iconv iconv&nbsp;options&nbsp;-f&nbsp;from-encoding&nbsp;-t&nbsp;to-encoding&nbsp;inputfile(s) -f\u6216\u2013from-code\u8868\u660e\u4e86\u8f93\u5165\u7f16\u7801\uff0c\u800c-t\u6216\u2013to-encoding\u6307\u5b9a\u4e86\u8f93\u51fa\u7f16\u7801\u3002 \u5217\u51fa\u6240\u6709\u652f\u6301\u7684\u7f16\u7801\u5b57\u7b26\u96c6 iconv \u6587\u4ef6\u7f16\u7801\u8f6c\u6362\u7684\u4f8b\u5b50 iconv \u5c06\u6587\u4ef6\u4ece ISO-8859-1 \u7f16\u7801\u8f6c\u6362\u4e3a UTF-8 \u7f16\u7801\u3002 \u5982\u679c\u8f93\u51fa\u7f16\u7801\u540e\u9762\u6dfb\u52a0\u4e86\/\/IGNORE\u5b57\u7b26\u4e32\uff0c\u90a3\u4e9b\u4e0d\u80fd\u88ab\u8f6c\u6362\u7684\u5b57\u7b26\u5c06\u4e0d\u4f1a\u88ab\u8f6c\u6362\uff0c\u5e76\u4e14\u5728\u8f6c\u6362\u540e\uff0c\u7a0b\u5e8f\u4f1a\u663e\u793a\u4e00\u6761\u9519\u8bef\u4fe1\u606f\u3002 \u5982\u679c\u5b57\u7b26\u4e32\/\/TRANSLIT\u88ab\u6dfb\u52a0\u5230\u4e86\u4e0a\u9762\u4f8b\u5b50\u4e2d\u7684\u8f93\u51fa\u7f16\u7801\u4e4b\u540e (UTF-8\/\/TRANSLIT)\uff0c\u5f85\u8f6c\u6362\u7684\u5b57\u7b26\u4f1a\u5c3d\u91cf\u91c7\u7528\u5f62\u8bd1\u539f\u5219\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u67d0\u4e2a\u5b57\u7b26\u5728\u8f93\u51fa\u7f16\u7801\u65b9\u6848\u4e2d\u4e0d\u80fd\u88ab\u8868\u793a\u7684\u8bdd\uff0c\u5b83\u5c06\u4f1a\u88ab\u66ff\u6362\u4e3a\u4e00\u4e2a\u5f62\u72b6\u6bd4\u8f83\u76f8\u4f3c\u7684\u5b57\u7b26\u3002 \u5982\u679c\u4e00\u4e2a\u5b57\u7b26\u4e0d\u5728\u8f93\u51fa\u7f16\u7801\u4e2d\uff0c\u800c\u4e14\u4e0d\u80fd\u88ab\u5f62\u8bd1\uff0c\u5b83\u5c06\u4f1a\u5728\u8f93\u51fa\u6587\u4ef6\u4e2d\u88ab\u4e00\u4e2a\u95ee\u53f7\u6807\u8bb0?\u4ee3\u66ff\u3002 \u5c06\u591a\u4e2a\u6587\u4ef6\u8f6c\u6362\u4e3a UTF-8 \u7f16\u7801\u53ef\u4ee5\u5229\u7528shell\u811a\u672c #!\/bin\/bash ###&nbsp;\u5c06&nbsp;values_here&nbsp;\u66ff\u6362\u4e3a\u8f93\u5165\u7f16\u7801 FROM_ENCODING=&#8221;value_here&#8221; ###&nbsp;\u8f93\u51fa\u7f16\u7801&nbsp;(UTF-8) TO_ENCODING=&#8221;UTF-8&#8243; ###&nbsp;\u8f6c\u6362\u547d\u4ee4 CONVERT=&#8221;&nbsp;iconv&nbsp;&nbsp;-f&nbsp;&nbsp;&nbsp;$FROM_ENCODING&nbsp;&nbsp;-t&nbsp;&nbsp;&nbsp;$TO_ENCODING&#8221; ###&nbsp;\u4f7f\u7528\u5faa\u73af\u8f6c\u6362\u591a\u4e2a\u6587\u4ef6 for&nbsp;&nbsp;file&nbsp;&nbsp;in&nbsp;&nbsp;*.txt;&nbsp;do $CONVERT&nbsp;&nbsp;&nbsp;&#8220;$file&#8221;&nbsp;&nbsp;&nbsp;-o&nbsp;&nbsp;&#8220;${file%.txt}.utf8.converted&#8221; done exit \u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u8f6c\u6362\u6587\u4ef6\u7684\u7f16\u7801\u683c\u5f0f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-51823","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=51823"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51823\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=51823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=51823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=51823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}