{"id":159677,"date":"2019-10-09T08:10:00","date_gmt":"2019-10-09T00:10:00","guid":{"rendered":"https:\/\/gulass.cn\/?p=159677"},"modified":"2019-09-26T15:16:52","modified_gmt":"2019-09-26T07:16:52","slug":"how-linux-delete","status":"publish","type":"post","link":"https:\/\/gulass.cn\/how-linux-delete.html","title":{"rendered":"\u51e0\u79cd\u5728 Linux \u4e2d\u5220\u9664\u6587\u672c\u4e2d\u56de\u8f66\u5b57\u7b26\u7684\u7b80\u5355\u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5f53\u56de\u8f66\u5b57\u7b26\uff08Ctrl+M\uff09\u8ba9\u4f60\u7d27\u5f20\u65f6\uff0c\u522b\u62c5\u5fc3\u3002\u6709\u51e0\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6d88\u9664\u5b83\u4eec\u3002\u201c\u56de\u8f66\u201d\u5b57\u7b26\u53ef\u4ee5\u5f80\u56de\u8ffd\u6eaf\u5f88\u957f\u4e00\u6bb5\u65f6\u95f4 \u2014\u2014 \u65e9\u5728\u6253\u5b57\u673a\u4e0a\u5c31\u6709\u4e00\u4e2a\u673a\u68b0\u88c5\u7f6e\u6216\u6760\u6746\u5c06\u627f\u8f7d\u7eb8\u6eda\u7b52\u7684\u673a\u67b6\u79fb\u5230\u53f3\u8fb9\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u91cd\u65b0\u5728\u5de6\u4fa7\u8f93\u5165\u5b57\u6bcd\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4ed6\u4eec\u5728 Windows \u4e0a\u7684\u6587\u672c\u6587\u4ef6\u4e0a\u4fdd\u7559\u4e86\u5b83\uff0c\u4f46\u4ece\u672a\u5728 Linux \u7cfb\u7edf\u4e0a\u4f7f\u7528\u8fc7\u3002\u5f53\u4f60\u5c1d\u8bd5\u5728 Linux \u4e0a\u5904\u7406\u5728 Windows \u4e0a\u521b\u5efa\u7684\u6587\u4ef6\u65f6\uff0c\u8fd9\u79cd\u4e0d\u517c\u5bb9\u6027\u6709\u65f6\u4f1a\u5bfc\u81f4\u95ee\u9898\uff0c\u4f46\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u5bb9\u6613\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n

\u5982\u679c\u4f60\u4f7f\u7528 od\uff08\u516b\u8fdb\u5236\u8f6c\u50a8octal dump\uff09\u547d\u4ee4\u67e5\u770b\u6587\u4ef6\uff0c\u90a3\u4e48\u56de\u8f66\uff08\u4e5f\u7528 Ctrl+M \u4ee3\u8868\uff09\u5b57\u7b26\u5c06\u663e\u793a\u4e3a\u516b\u8fdb\u5236\u7684 15\u3002\u5b57\u7b26 CRLF \u901a\u5e38\u7528\u4e8e\u8868\u793a Windows \u6587\u672c\u6587\u4ef6\u4e2d\u7684\u4e00\u884c\u7ed3\u675f\u7684\u56de\u8f66\u7b26\u548c\u6362\u884c\u7b26\u5e8f\u5217\u3002\u90a3\u4e9b\u6ce8\u610f\u770b\u516b\u8fdb\u5236\u8f6c\u50a8\u7684\u4f1a\u770b\u5230 \\r\\n\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0cLinux \u6587\u672c\u4ec5\u4ee5\u6362\u884c\u7b26\u7ed3\u675f\u3002<\/p>\n

\u8fd9\u6709\u4e00\u4e2a od \u8f93\u51fa\u7684\u793a\u4f8b\uff0c\u9ad8\u4eae\u663e\u793a\u4e86\u884c\u4e2d\u7684 CRLF \u5b57\u7b26\uff0c\u4ee5\u53ca\u5b83\u7684\u516b\u8fdb\u5236\u3002<\/p>\n

$ od -bc testfile.txt\r\n0000000 124 150 151 163 040 151 163 040 141 040 164 145 163 164 040 146\r\n          T   h   i   s       i   s       a       t   e   s   t       f\r\n0000020 151 154 145 040 146 162 157 155 040 127 151 156 144 157 167 163\r\n          i   l   e       f   r   o   m       W   i   n   d   o   w   s\r\n0000040 056 015 012 111 164 047 163 040 144 151 146 146 145 162 145 156  < ==\r\n          .  \\r  \\n   I   t   '   s       d   i   f   f   e   r   e   n  <==\r\n0000060 164 040 164 150 141 156 040 141 040 125 156 151 170 040 164 145\r\n          t       t   h   a   n       a       U   n   i   x       t   e\r\n0000100 170 164 040 146 151 154 145 015 012 167 157 165 154 144 040 142  <==\r\n          x   t       f   i   l   e  \\r  \\n   w   o   u   l   d       b  <==<\/pre>\n

\u867d\u7136\u8fd9\u4e9b\u5b57\u7b26\u4e0d\u662f\u5927\u95ee\u9898\uff0c\u4f46\u662f\u5f53\u4f60\u60f3\u8981\u4ee5\u67d0\u79cd\u65b9\u5f0f\u89e3\u6790\u6587\u672c\uff0c\u5e76\u4e14\u4e0d\u5e0c\u671b\u5c31\u5b83\u4eec\u662f\u5426\u5b58\u5728\u8fdb\u884c\u7f16\u7801\u65f6\uff0c\u8fd9\u6709\u65f6\u5019\u4f1a\u4ea7\u751f\u5e72\u6270\u3002<\/p>\n

3 \u79cd\u4ece\u6587\u672c\u4e2d\u5220\u9664\u56de\u8f66\u7b26\u7684\u65b9\u6cd5<\/strong><\/div>\n

\u5e78\u8fd0\u7684\u662f\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8f7b\u677e\u5220\u9664\u56de\u8f66\u7b26\u3002\u8fd9\u6709\u4e09\u4e2a\u9009\u62e9\uff1a<\/p>\n

dos2unix<\/strong><\/span><\/div>\n

\u4f60\u53ef\u80fd\u4f1a\u5728\u5b89\u88c5\u65f6\u9047\u5230\u9ebb\u70e6\uff0c\u4f46 dos2unix \u53ef\u80fd\u662f\u5c06 Windows \u6587\u672c\u8f6c\u6362\u4e3a Unix\/Linux \u6587\u672c\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u3002\u4e00\u4e2a\u547d\u4ee4\u5e26\u4e0a\u4e00\u4e2a\u53c2\u6570\u5c31\u884c\u4e86\u3002\u4e0d\u9700\u8981\u7b2c\u4e8c\u4e2a\u6587\u4ef6\u540d\u3002\u8be5\u6587\u4ef6\u4f1a\u88ab\u76f4\u63a5\u66f4\u6539\u3002<\/p>\n

$ dos2unix testfile.txt\r\ndos2unix: converting file testfile.txt to Unix format...<\/pre>\n

\u4f60\u5e94\u8be5\u4f1a\u53d1\u73b0\u6587\u4ef6\u957f\u5ea6\u51cf\u5c11\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u5b83\u5305\u542b\u7684\u884c\u6570\u3002\u5305\u542b 100 \u884c\u7684\u6587\u4ef6\u53ef\u80fd\u4f1a\u7f29\u5c0f 99 \u4e2a\u5b57\u7b26\uff0c\u56e0\u4e3a\u53ea\u6709\u6700\u540e\u4e00\u884c\u4e0d\u4f1a\u4ee5 CRLF \u5b57\u7b26\u7ed3\u5c3e\u3002<\/p>\n

\u4e4b\u524d\uff1a<\/p>\n

-rw-rw-r--   1 shs  shs        121 Sep 14 19:11 testfile.txt<\/pre>\n

\u4e4b\u540e\uff1a<\/p>\n

-rw-rw-r--   1 shs  shs        118 Sep 14 19:12 testfile.txt<\/pre>\n

\u5982\u679c\u4f60\u9700\u8981\u8f6c\u6362\u5927\u91cf\u6587\u4ef6\uff0c\u4e0d\u7528\u6bcf\u6b21\u4fee\u590d\u4e00\u4e2a\u3002\u76f8\u53cd\uff0c\u5c06\u5b83\u4eec\u5168\u90e8\u653e\u5728\u4e00\u4e2a\u76ee\u5f55\u4e2d\u5e76\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

$ find . -type f -exec dos2unix {} \\;<\/pre>\n

\u5728\u6b64\u547d\u4ee4\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 find \u67e5\u627e\u5e38\u89c4\u6587\u4ef6\uff0c\u7136\u540e\u8fd0\u884c dos2unix \u547d\u4ee4\u4e00\u6b21\u8f6c\u6362\u4e00\u4e2a\u3002\u547d\u4ee4\u4e2d\u7684 {} \u5c06\u88ab\u66ff\u6362\u4e3a\u6587\u4ef6\u540d\u3002\u8fd0\u884c\u65f6\uff0c\u4f60\u5e94\u8be5\u5904\u4e8e\u5305\u542b\u6587\u4ef6\u7684\u76ee\u5f55\u4e2d\u3002\u6b64\u547d\u4ee4\u53ef\u80fd\u4f1a\u635f\u574f\u5176\u4ed6\u7c7b\u578b\u7684\u6587\u4ef6\uff0c\u4f8b\u5982\u9664\u4e86\u6587\u672c\u6587\u4ef6\u5916\u5728\u4e0a\u4e0b\u6587\u4e2d\u5305\u542b\u516b\u8fdb\u5236 15 \u7684\u6587\u4ef6\uff08\u5982\uff0c\u955c\u50cf\u6587\u4ef6\u4e2d\u7684\u5b57\u8282\uff09\u3002<\/p>\n

sed<\/strong><\/span><\/div>\n

\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6d41\u7f16\u8f91\u5668 sed \u6765\u5220\u9664\u56de\u8f66\u7b26\u3002\u4f46\u662f\uff0c\u4f60\u5fc5\u987b\u63d0\u4f9b\u7b2c\u4e8c\u4e2a\u6587\u4ef6\u540d\u3002\u4ee5\u4e0b\u662f\u4f8b\u5b50\uff1a<\/p>\n

$ sed -e \u201cs\/^M\/\/\u201d before.txt > after.txt<\/pre>\n

\u4e00\u4ef6\u9700\u8981\u6ce8\u610f\u7684\u91cd\u8981\u7684\u4e8b\u60c5\u662f\uff0c\u8bf7\u4e0d\u8981\u8f93\u5165\u4f60\u770b\u5230\u7684\u5b57\u7b26\u3002\u4f60\u5fc5\u987b\u6309\u4e0b Ctrl+V \u540e\u8ddf Ctrl+M \u6765\u8f93\u5165 ^M\u3002s \u662f\u66ff\u6362\u547d\u4ee4\u3002\u659c\u6760\u5c06\u6211\u4eec\u8981\u67e5\u627e\u7684\u6587\u672c\uff08Ctrl + M\uff09\u548c\u8981\u66ff\u6362\u7684\u6587\u672c\uff08\u8fd9\u91cc\u4e3a\u7a7a\uff09\u5206\u5f00\u3002<\/p>\n

vi<\/strong><\/span><\/div>\n

\u4f60\u751a\u81f3\u53ef\u4ee5\u4f7f\u7528 vi \u5220\u9664\u56de\u8f66\u7b26\uff08Ctrl+M\uff09\uff0c\u4f46\u8fd9\u91cc\u5047\u8bbe\u4f60\u6ca1\u6709\u6253\u5f00\u6570\u767e\u4e2a\u6587\u4ef6\uff0c\u6216\u8bb8\u4e5f\u5728\u505a\u4e00\u4e9b\u5176\u4ed6\u7684\u4fee\u6539\u3002\u4f60\u53ef\u4ee5\u952e\u5165 : \u8fdb\u5165\u547d\u4ee4\u884c\uff0c\u7136\u540e\u8f93\u5165\u4e0b\u9762\u7684\u5b57\u7b26\u4e32\u3002\u4e0e sed \u4e00\u6837\uff0c\u547d\u4ee4\u4e2d ^M \u9700\u8981\u901a\u8fc7 Ctrl+V \u8f93\u5165 ^\uff0c\u7136\u540e Ctrl+M \u63d2\u5165 M\u3002%s \u662f\u66ff\u6362\u64cd\u4f5c\uff0c\u659c\u6760\u518d\u6b21\u5c06\u6211\u4eec\u8981\u5220\u9664\u7684\u5b57\u7b26\u548c\u6211\u4eec\u60f3\u8981\u66ff\u6362\u5b83\u7684\u6587\u672c\uff08\u7a7a\uff09\u5206\u5f00\u3002 g\uff08\u5168\u5c40\uff09\u610f\u5473\u5728\u6240\u6709\u884c\u4e0a\u6267\u884c\u3002<\/p>\n

:%s\/^M\/\/g<\/pre>\n
\u603b\u7ed3<\/strong><\/div>\n

dos2unix \u547d\u4ee4\u53ef\u80fd\u662f\u6700\u5bb9\u6613\u8bb0\u4f4f\u7684\uff0c\u4e5f\u662f\u4ece\u6587\u672c\u4e2d\u5220\u9664\u56de\u8f66\u7684\u6700\u53ef\u9760\u7684\u65b9\u6cd5\u3002\u5176\u4ed6\u9009\u62e9\u4f7f\u7528\u8d77\u6765\u6709\u70b9\u56f0\u96be\uff0c\u4f46\u5b83\u4eec\u63d0\u4f9b\u76f8\u540c\u7684\u57fa\u672c\u529f\u80fd\u3002<\/p>\n

via: https:\/\/www.networkworld.com\/article\/3438857\/how-to-remove-carriage-returns-from-text-files-on-linux.html<\/p>\n

\u4f5c\u8005\uff1aSandra Henry-Stocker \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1ageekpi \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4ed6\u4eec\u5728 Windows \u4e0a\u7684\u6587\u672c\u6587\u4ef6\u4e0a\u4fdd\u7559\u4e86\u5b83\uff0c\u4f46\u4ece\u672a\u5728 Linux \u7cfb\u7edf\u4e0a\u4f7f\u7528\u8fc7\u3002\u5f53\u4f60\u5c1d\u8bd5\u5728 Linux \u4e0a […]<\/p>\n","protected":false},"author":1482,"featured_media":133028,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-159677","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/159677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=159677"}],"version-history":[{"count":6,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/159677\/revisions"}],"predecessor-version":[{"id":159769,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/159677\/revisions\/159769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/133028"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=159677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=159677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=159677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}