{"id":2416,"date":"2015-07-25T17:19:19","date_gmt":"2015-07-25T09:19:19","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2416"},"modified":"2015-07-25T17:19:19","modified_gmt":"2015-07-25T09:19:19","slug":"bash%e4%b8%ad%e7%9a%84%e5%91%bd%e4%bb%a4%e5%8e%86%e5%8f%b2tips%e5%b0%8f%e7%bb%93","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2416.html","title":{"rendered":"Bash\u4e2d\u7684[\u547d\u4ee4\u5386\u53f2]tips\u5c0f\u7ed3"},"content":{"rendered":"<p>\u5728\u4e4b\u524d\u5c31\u8bb0\u5f55\u8fc7\u4e0d\u5c11\u548cBash\u7684\u547d\u4ee4\u5386\u53f2\u76f8\u5173\u7684\u5c0f\u6280\u5de7\uff0c\u6bd4\u5982\uff1a\u7edf\u8ba1\u6700\u5e38\u7528\u768410\u4e2a\u547d\u4ee4\u3001\u4ee5root\u8eab\u4efd\u6267\u884c\u4e0a\u4e00\u6761\u547d\u4ee4\u3001\u5feb\u901f\u83b7\u53d6\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u2026\u2026<\/p>\n<p>\u540e\u6765\u770b\u5230\u4e00\u7bc7\u6587\u7ae0\uff1a<a href=\"http:\/\/talk.linuxtoy.org\/using-cli\/\" target=\"_blank\">\u50cf\u9ed1\u5ba2\u4e00\u6837\u4f7f\u7528 Linux \u547d\u4ee4\u884c<\/a>\uff0c\u5b66\u4e60\u5230\u4e86\u4e0d\u5c11\uff0c\u540c\u65f6\u53c8\u53bb\u7f51\u4e0a\u641c\u4e86\u66f4\u591a\u7684\u8d44\u6599\uff0c\u8bb0\u5f55\u3001\u603b\u7ed3\u6210\u4e86\u672c\u6587\u3002<\/p>\n<h6>0.\u6700\u5e38\u7528\u768410\u4e2a\u547d\u4ee4<\/h6>\n<pre class=\"lang:default decode:true\">history |\n&gt; awk '{CMD[$2]++;count++;} END{ for(a in CMD) print CMD[a],CMD[a]\/count*100 \"% \" a;}' |\n&gt; grep -v \".\/\" |\n&gt; column -c3 -s \" \" -t |\n&gt; sort -nr |\n&gt; nl |\n&gt; head -n 10<\/pre>\n<h6>1.\u4ee5root\u8eab\u4efd\u6267\u884c\u4e0a\u4e00\u6761\u547d\u4ee4<\/h6>\n<pre class=\"lang:default decode:true\"># \u4ee5root\u8eab\u4efd\u6267\u884c\u4e0a\u4e00\u6761\u547d\u4ee4\n$ sudo !!<\/pre>\n<h6>2.\u66ff\u6362\u4e0a\u4e00\u6761\u547d\u4ee4\u7684[\u90e8\u5206]\u5185\u5bb9<\/h6>\n<pre class=\"lang:default decode:true\">#\u4f7f\u7528 ^old^new \u6362\u6389\u8f93\u9519\u6216\u8f93\u5c11\u7684\u90e8\u5206( !:s\/old\/new )\n#\u4f7f\u7528 !:gs\/old\/new \u5c06 old \u5168\u90e8\u6362\u6210 new\n$ echo \"a nginx, web nginx server, nginx...\"\na nginx, web nginx server, nginx...\n$ ^nginx^apache\necho \"a apache, web nginx server, nginx...\"\na apache, web nginx server, nginx...\n$\n$ echo \"a nginx, web nginx server, nginx...\"\na nginx, web nginx server, nginx...\n$ !:gs\/nginx\/apache\necho \"a apache, web apache server, apache...\"\na apache, web apache server, apache...\n$<\/pre>\n<h6>3.\u5feb\u901f\u83b7\u53d6\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u6700\u540e\u4e00\u4f4d\u53c2\u6570<\/h6>\n<pre class=\"lang:default decode:true\">#\u901a\u8fc7 !$ \u5f97\u5230\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u6700\u540e\u4e00\u4f4d\u53c2\u6570\n#\u5feb\u6377\u952e [Alt + .]<\/pre>\n<h6>4.\u5feb\u901f\u83b7\u53d6\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u7b2c\u4e00\u4f4d\u53c2\u6570<\/h6>\n<pre class=\"lang:default decode:true\">#\u901a\u8fc7 !^ \u5f97\u5230\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\n#\u5feb\u6377\u952e [Ctrl + Alt + y]<\/pre>\n<h6>5.\u5982\u4f55\u83b7\u53d6\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u591a\u4e2a\u53c2\u6570<\/h6>\n<pre class=\"lang:default decode:true\">#\u901a\u8fc7 !:n \u5f97\u5230\u4e0a\u4e00\u6761\u547d\u4ee4\u7b2c n \u4e2a\u53c2\u6570\n$ touch foo.txt bar.txt baz.txt\n$ vim !:2\nvim bar.txt\n\n#\u901a\u8fc7 !:x-y \u5f97\u5230\u4e0a\u4e00\u6761\u547d\u4ee4\u4ece x \u5230 y \u7684\u53c2\u6570\n$ touch foo.txt bar.txt baz.txt\n$ vim !:1-2\nvim foo.txt bar.txt\n\n#\u901a\u8fc7 !:n* \u5f97\u5230\u4e0a\u4e00\u6761\u547d\u4ee4\u4ece n \u5f00\u59cb\u5230\u6700\u540e\u7684\u53c2\u6570\n$ cat \/etc\/resolv.conf \/etc\/hosts \/etc\/hostname\n$ vim !:2*\nvim \/etc\/hosts \/etc\/hostname\n\n#\u901a\u8fc7 !* \u5f97\u5230\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u6240\u6709\u53c2\u6570\n$ touch foo.txt bar.txt hey.txt haha.txt hello.txt\n$ cat !*\ncat foo.txt bar.txt hey.txt haha.txt hello.txt<\/pre>\n<h6>6.\u5982\u4f55\u83b7\u53d6\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u547d\u4ee4\u540d<\/h6>\n<pre class=\"lang:default decode:true\">#\u901a\u8fc7 !# \u5f97\u5230\u4e0a\u4e00\u6761\u547d\u4ee4\u7684\u547d\u4ee4\u540d<\/pre>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a href=\"http:\/\/talk.linuxtoy.org\/using-cli\/\" target=\"_blank\">http:\/\/talk.linuxtoy.org\/using-cli\/<\/a><\/li>\n<li><a href=\"http:\/\/ixyzero.com\/blog\/archives\/171.html\" target=\"_blank\">http:\/\/ixyzero.com\/blog\/archives\/171.html<\/a><\/li>\n<li><a href=\"http:\/\/www.letuknowit.com\/post\/78.html\" target=\"_blank\">http:\/\/www.letuknowit.com\/post\/78.html<\/a><\/li>\n<\/ul>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e4b\u524d\u5c31\u8bb0\u5f55\u8fc7\u4e0d\u5c11\u548cBash\u7684\u547d\u4ee4\u5386\u53f2\u76f8\u5173\u7684\u5c0f\u6280\u5de7\uff0c\u6bd4\u5982\uff1a\u7edf\u8ba1\u6700\u5e38\u7528\u768410\u4e2a\u547d\u4ee4\u3001\u4ee5root\u8eab\u4efd\u6267\u884c\u4e0a\u4e00\u6761\u547d\u4ee4 [&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],"tags":[83,92,30],"class_list":["post-2416","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","tag-bash","tag-history","tag-linux"],"views":4596,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2416","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=2416"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2416\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}