{"id":2297,"date":"2015-07-04T17:11:38","date_gmt":"2015-07-04T09:11:38","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2297"},"modified":"2015-07-04T17:11:38","modified_gmt":"2015-07-04T09:11:38","slug":"collect%e5%91%bd%e4%bb%a4%e8%a1%8c%e8%89%ba%e6%9c%af","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2297.html","title":{"rendered":"[collect]\u547d\u4ee4\u884c\u827a\u672f"},"content":{"rendered":"<p>\u6807\u9898\u4e2d\u7684\u201c\u547d\u4ee4\u884c\u827a\u672f\u201d\u6307\u7684\u662f\u5728GitHub\u4e0a\u770b\u5230\u7684\u00a0<a href=\"https:\/\/github.com\/jlevy\/the-art-of-command-line\" target=\"_blank\">the-art-of-command-line<\/a> \uff0c\u4ece\u4e2d\u5b66\u4e60\u5230\u4e86\u4e0d\u5c11\u4e4b\u524d\u6211\u4e0d\u77e5\u9053\u6216\u4e0d\u719f\u6089\u7684\u547d\u4ee4\uff0c\u5728\u6b64\u505a\u4e2a\u8bb0\u5f55\uff0c\u4e0d\u5b9a\u671f\u66f4\u65b0\uff1a<\/p>\n<p>==<\/p>\n<ul>\n<li>man<\/li>\n<li>apropos<\/li>\n<li>help [-d]<\/li>\n<li>type<\/li>\n<li>whereis\/which<\/li>\n<\/ul>\n<p>\u4e86\u89e3 ssh\uff0c\u4ee5\u53ca\u57fa\u672c\u7684\u65e0\u5bc6\u7801\u8ba4\u8bc1\uff0cssh-agent\uff0cssh-add \u7b49<\/p>\n<ul>\n<li>df<\/li>\n<li>mount<\/li>\n<li>fdisk<\/li>\n<li>mkfs<\/li>\n<li>lsblk<\/li>\n<\/ul>\n<p>ln \u548c ln -s (\u4e86\u89e3\u786c\u94fe\u63a5\u4e0e\u8f6f\u94fe\u63a5\u7684\u533a\u522b)<\/p>\n<ul>\n<li>Ctrl-a\/e\/u\/k\/l\u00a0 #Useful<\/li>\n<li>Alt-b\/f\u00a0\u00a0\u00a0\u00a0 #Useful<\/li>\n<li>man readline<\/li>\n<\/ul>\n<h6>\u548c\u4e0a\u4e00\u4e2a\u547d\u4ee4\u76f8\u5173\u7684\u53c2\u6570\u3001\u547d\u4ee4\u5185\u5bb9\uff1a<\/h6>\n<ul>\n<li>!^<\/li>\n<li>!$<\/li>\n<li>!*<\/li>\n<li>!!<\/li>\n<\/ul>\n<p>\u4f7f\u7528 netstat -lntp \u6216 ss -plat \u68c0\u67e5\u54ea\u4e9b\u8fdb\u7a0b\u5728\u76d1\u542c\u7aef\u53e3<\/p>\n<p>=<\/p>\n<p>\u5728 Bash \u811a\u672c\u4e2d\uff0c\u4f7f\u7528 set -x \u53bb\u8c03\u8bd5\u8f93\u51fa\uff0c\u5c3d\u53ef\u80fd\u7684\u4f7f\u7528\u4e25\u683c\u6a21\u5f0f\uff0c\u4f7f\u7528 set -e \u4ee4\u811a\u672c\u5728\u53d1\u751f\u9519\u8bef\u65f6\u9000\u51fa\u800c\u4e0d\u662f\u7ee7\u7eed\u8fd0\u884c\uff0c\u4f7f\u7528 set -o pipefail \u4e25\u8c28\u5730\u5bf9\u5f85\u9519\u8bef(\u5c3d\u7ba1\u95ee\u9898\u53ef\u80fd\u5f88\u5fae\u5999)\u3002\u5f53\u7275\u626f\u5230\u5f88\u591a\u811a\u672c\u65f6\uff0c\u4f7f\u7528 trap\u3002<\/p>\n<pre class=\"lang:default decode:true\"># \u5b50 shell(\u4f7f\u7528\u62ec\u53f7(...))\u662f\u4e00\u79cd\u4fbf\u6377\u7684\u65b9\u5f0f\n# do something in current dir\n(cd \/some\/other\/dir &amp;&amp; other-command)\n# continue in original dir<\/pre>\n<pre class=\"lang:default decode:true\">\u901a\u8fc7\u4f7f\u7528 &lt;(some command) \u53ef\u4ee5\u5c06\u8f93\u51fa\u89c6\u4e3a\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5bf9\u6bd4\u672c\u5730\u6587\u4ef6 \/etc\/hosts \u548c\u4e00\u4e2a\u8fdc\u7a0b\u6587\u4ef6\uff1a\ndiff \/etc\/hosts &lt;(ssh somehost cat \/etc\/hosts)<\/pre>\n<p>\u4f7f\u7528 man ascii \u67e5\u770b\u5177\u6709\u5341\u516d\u8fdb\u5236\u548c\u5341\u8fdb\u5236\u503c\u7684ASCII\u8868\u3002man unicode\uff0cman utf-8\uff0c\u4ee5\u53ca man latin1 \u6709\u52a9\u4e8e\u4f60\u53bb\u4e86\u89e3\u901a\u7528\u7684\u7f16\u7801\u4fe1\u606f\u3002<\/p>\n<p>=<\/p>\n<p>\u4f7f\u7528 screen \u6216 tmux \u6765\u4f7f\u7528\u591a\u4e2a\u5c4f\u5e55\uff0c\u5f53\u4f60\u5728\u4f7f\u7528 ssh \u65f6(\u4fdd\u5b58 session \u4fe1\u606f)\u5c06\u5c24\u4e3a\u6709\u7528\u3002\u53e6\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u89e3\u51b3\u65b9\u6848\u662f dtach\u3002<\/p>\n<p>=<\/p>\n<p>\u5bf9 ssh \u8bbe\u7f6e\u505a\u4e00\u4e9b\u5c0f\u4f18\u5316\u53ef\u80fd\u662f\u5f88\u6709\u7528\u7684\uff0c\u4f8b\u5982\u8fd9\u4e2a ~\/.ssh\/config \u6587\u4ef6\u5305\u542b\u4e86\u9632\u6b62\u7279\u5b9a\u73af\u5883\u4e0b\u65ad\u5f00\u8fde\u63a5\u3001\u538b\u7f29\u6570\u636e\u3001\u591a\u901a\u9053\u7b49\u9009\u9879\uff1a<\/p>\n<pre class=\"lang:default decode:true\">    TCPKeepAlive=yes\n    ServerAliveInterval=15\n    ServerAliveCountMax=6\n    Compression=yes\n    ControlMaster auto\n    ControlPath \/tmp\/%r@%h:%p\n    ControlPersist yes<\/pre>\n<p>\u83b7\u53d6\u6587\u4ef6\u7684\u516b\u8fdb\u5236\u683c\u5f0f\u6743\u9650\uff0c\u4f7f\u7528\u7c7b\u4f3c\u5982\u4e0b\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:default decode:true\">man stat\nstat -c '%A %a %n' \/etc\/timezone<\/pre>\n<p>\u4f7f\u7528 jq \u5904\u7406 JSON<\/p>\n<p>\u5982\u679c\u4f60\u4e0d\u5f97\u4e0d\u5904\u7406 XML\uff0cxmlstarlet \u5b9d\u5200\u672a\u8001<\/p>\n<p>\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 cut\uff0cpaste \u548c join \u6765\u66f4\u6539\u6587\u4ef6\u3002\u5f88\u591a\u4eba\u90fd\u4f1a\u4f7f\u7528 cut\uff0c\u4f46\u51e0\u4e4e\u90fd\u4e0d\u4f1a\u4f7f\u7528 join<\/p>\n<p>=<\/p>\n<p>\u4e86\u89e3\u8bed\u8a00\u73af\u5883\u5bf9\u8bb8\u591a\u547d\u4ee4\u884c\u5de5\u5177\u7684\u5fae\u5999\u5f71\u54cd\uff0c\u5305\u62ec\u6392\u5e8f\u7684\u987a\u5e8f\u548c\u6027\u80fd\u3002\u5927\u591a\u6570 Linux \u7684\u5b89\u88c5\u8fc7\u7a0b\u4f1a\u5c06 LANG \u6216\u5176\u4ed6\u6709\u5173\u7684\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u7b26\u5408\u672c\u5730\u7684\u8bbe\u7f6e\u3002\u610f\u8bc6\u5230\u5f53\u4f60\u6539\u53d8\u8bed\u8a00\u73af\u5883\u65f6\uff0c\u6392\u5e8f\u7684\u7ed3\u679c\u53ef\u80fd\u4f1a\u6539\u53d8\u3002\u660e\u767d\u56fd\u9645\u5316\u53ef\u80fd\u4f1a\u65f6 sort \u6216\u5176\u4ed6\u547d\u4ee4\u8fd0\u884c\u6548\u7387\u4e0b\u964d\u8bb8\u591a\u500d\u3002\u67d0\u4e9b\u60c5\u51b5\u4e0b(\u4f8b\u5982\u96c6\u5408\u8fd0\u7b97)\u4f60\u53ef\u4ee5\u653e\u5fc3\u7684\u4f7f\u7528 export LC_ALL=C \u6765\u5ffd\u7565\u6389\u56fd\u9645\u5316\u5e76\u4f7f\u7528\u57fa\u4e8e\u5b57\u8282\u7684\u987a\u5e8f\u3002<\/p>\n<p>=<\/p>\n<p>\u66ff\u6362\u4e00\u4e2a\u6216\u591a\u4e2a\u6587\u4ef6\u4e2d\u51fa\u73b0\u7684\u5b57\u7b26\u4e32:<\/p>\n<pre class=\"lang:default decode:true\">perl -pi.bak -e 's\/old-string\/new-string\/g' my-files-*.txt<\/pre>\n<p>\u4f9d\u636e\u67d0\u79cd\u6a21\u5f0f\u6279\u91cf\u91cd\u547d\u540d\u591a\u4e2a\u6587\u4ef6\uff0c\u4f7f\u7528 rename\u3002\u5bf9\u4e8e\u590d\u6742\u7684\u91cd\u547d\u540d\u89c4\u5219\uff0crepren \u6216\u8bb8\u6709\u5e2e\u52a9\u3002<\/p>\n<pre class=\"lang:default decode:true\"># Recover backup files foo.bak -&gt; foo:\nrename 's\/\\.bak$\/\/' *.bak\n# Full rename of filenames\uff0cdirectories\uff0cand contents foo -&gt; bar:\nrepren --full --preserve-case --from foo --to bar .<\/pre>\n<p>=\u5f85\u7eed=<\/p>\n<p>&nbsp;<\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"https:\/\/github.com\/jlevy\/the-art-of-command-line\/blob\/master\/README.md\" target=\"_blank\">https:\/\/github.com\/jlevy\/the-art-of-command-line\/blob\/master\/README.md<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/jlevy\/the-art-of-command-line\/blob\/master\/README-zh.md\" target=\"_blank\">https:\/\/github.com\/jlevy\/the-art-of-command-line\/blob\/master\/README-zh.md<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6807\u9898\u4e2d\u7684\u201c\u547d\u4ee4\u884c\u827a\u672f\u201d\u6307\u7684\u662f\u5728GitHub\u4e0a\u770b\u5230\u7684\u00a0the-art-of-command-line \uff0c\u4ece\u4e2d\u5b66\u4e60 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,12],"tags":[30,19],"class_list":["post-2297","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-tools","tag-linux","tag-tips"],"views":4708,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2297"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2297\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}