{"id":3164,"date":"2011-07-24T17:32:25","date_gmt":"2011-07-24T09:32:25","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3164"},"modified":"2011-07-24T21:21:32","modified_gmt":"2011-07-24T13:21:32","slug":"%e4%bd%bf%e7%94%a8grep%e6%9f%a5%e6%89%be%e6%8c%87%e5%ae%9a%e7%9b%ae%e5%bd%95%e4%b8%8b%e7%9a%84%e5%85%b3%e9%94%ae%e5%ad%97","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3164","title":{"rendered":"\u4f7f\u7528grep\u67e5\u627e\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u5173\u952e\u5b57"},"content":{"rendered":"<p>\u4e4b\u524d\u4e8e\u7ae5\u978b\u95ee\u6211\u5982\u4e0b\u95ee\u9898\uff1a<\/p>\n<p><strong>\u5728\/etc\u76ee\u5f55\u4e0b\u5982\u4f55\u67e5\u627e\u5305\u542b&#8217;root&#8217;\u5173\u952e\u5b57\u7684\u6240\u6709\u6587\u4ef6\uff1f<\/strong><\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6307\u5b9a\u7684\u6587\u4ef6\u6765\u8bf4\u901a\u5e38\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u6765\u67e5\u627e\u5173\u952e\u5b57\uff1a<\/p>\n<pre class=\"brush:c\">grep 'keyword' file<\/pre>\n<p>\u5982\u679c\u4f60\u61c2\u5f97\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u90a3\u4e48\u8fd8\u53ef\u4ee5\u5bf9\u5173\u952e\u5b57\u4f5c\u66f4\u7ec6\u81f4\u7684\u5339\u914d\u3002\u4f46\u662f\u5229\u7528grep\u67e5\u627e\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u6211\u5c1a\u4e0d\u6e05\u695a\uff0c\u901a\u8fc7man\u624b\u518c\u4ee5\u53ca\u8bba\u575b\u6c42\u52a9\u57fa\u672c\u89e3\u51b3\u4e86\u4e0a\u9762\u7684\u90a3\u4e2a\u95ee\u9898\u3002<\/p>\n<p><strong>1.\u5982\u4f55\u9012\u5f52\u67e5\u627e<\/strong><\/p>\n<p>grep\u901a\u5e38\u53ea\u80fd\u67e5\u627e\u6307\u5b9a\u6570\u76ee\u7684\u6587\u4ef6\uff0c\u5982\u679c\u9700\u8981\u67e5\u627e\u67d0\u4e2a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u5fc5\u987b\u6dfb\u52a0-R\u6216-r\u9009\u9879\u3002\u8fd9\u4e2a\u9009\u9879\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u5982\u679c\u6211\u4eec\u8981\u5220\u9664\u4e00\u4e2a\u975e\u7a7a\u7684\u76ee\u5f55\u90a3\u4e48\u4e5f\u5fc5\u987b\u5bf9rm\u547d\u4ee4\u6dfb\u52a0-r\u6216-R\u9009\u9879\u3002\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\u672c\u6587\u4e00\u5f00\u59cb\u6240\u63d0\u51fa\u7684\u95ee\u9898\uff1a<\/p>\n<pre class=\"brush:c\">grep -R 'boot' \/etc<\/pre>\n<p>\u8fd9\u6837\u597d\u50cf\u5df2\u7ecf\u89e3\u51b3\u4e86\u95ee\u9898\uff0c\u4e0d\u8fc7\u4ece\u8f93\u51fa\u7684\u7ed3\u679c\u6765\u770b\u6709\u4e00\u4e9b\u5339\u914d\u5e76\u4e0d\u7b26\u5408\u6211\u4eec\u7684\u8981\u6c42\u3002<\/p>\n<pre class=\"brush:c\">\/etc\/grub.d\/README:administrator.  For example, you can add an entry to boot another OS as\r\n\/etc\/grub.d\/20_memtest86+:if test -e \/boot\/memtest86+.bin ; then\r\n\/etc\/grub.d\/20_memtest86+:  prepare_boot_cache=\"$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e \"s\/^\/\r\n\\t\/\")\"<\/pre>\n<p>\u6bd4\u5982\u7b2c\u4e09\u884c\u6240\u5339\u914d\u7684root\u5e76\u4e0d\u662f\u4e00\u4e2a\u5355\u72ec\u7684\u8bcd\uff0c\u800c\u662f\u5305\u542b\u5728\u5176\u4ed6\u5b57\u7b26\u4e32\u4e2d\u3002<\/p>\n<p><strong>2.\u5b8c\u5168\u5339\u914d\u4e00\u4e2a\u8bcd<\/strong><\/p>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u5206\u6790\u6211\u4eec\u5f97\u77e5\u6211\u4eec\u9700\u8981\u7c7b\u4f3c\u4e0b\u9762\u7684\u4e3e\u4f8b\u90a3\u6837\u5339\u914droot\u5173\u952e\u5b57\uff1a<\/p>\n<p>I am a root<br \/>\nroot is me<br \/>\nI have root permission<\/p>\n<p>\u800c\u4e0d\u662f\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<p>rooter is me<br \/>\nI am rooter<br \/>\nI have rooter permission<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u589e\u52a0\u5176\u4ed6\u53c2\u6570\u4ee5\u8fbe\u5230\u5b8c\u5168\u5339\u914d\u4e00\u4e2a\u8bcd\u7684\u76ee\u7684\u3002grep\u4e2d\u4f7f\u7528-w\u9009\u9879\u6765\u5b8c\u5168\u5339\u914d\u4e00\u4e2a\u5355\u8bcd\u3002\u56e0\u6b64\u6211\u4eec\u7684\u89e3\u51b3\u65b9\u6cd5\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:c\">grep -R -w 'boot' \/etc<\/pre>\n<p><strong>3.\u66f4\u53cb\u597d\u7684\u6539\u8fdb<\/strong><\/p>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u547d\u4ee4\u5df2\u7ecf\u53ef\u4ee5\u8f83\u597d\u7684\u89e3\u51b3\u672c\u6587\u4e00\u5f00\u59cb\u63d0\u51fa\u7684\u95ee\u9898\u4e86\u3002\u4e0d\u8fc7\uff0c\u5176\u8f93\u51fa\u7ed3\u679c\u5f88\u957f\uff0c\u4e0d\u65b9\u4fbf\u6211\u4eec\u67e5\u770b\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u9700\u8981\u77e5\u9053\u8be5\u5173\u952e\u5b57\u4f4d\u4e8e\u88ab\u67e5\u627e\u6587\u4ef6\u7684\u54ea\u4e00\u884c\uff0c\u90a3\u4e48\u53ef\u4ee5\u52a0\u5165-n\u9009\u9879\uff1a<\/p>\n<pre class=\"brush:c\">grep -R -w -n 'boot' \/etc<\/pre>\n<p>\u6709\u65f6\u5019\u6211\u4eec\u53ea\u9700\u8981\u77e5\u9053\u8be5\u5173\u952e\u5b57\u5305\u542b\u5728\u90a3\u4e2a\u6587\u4ef6\u4e2d\uff0c\u56e0\u6b64\u6211\u4eec\u52a0\u5165-l\u9009\u9879\uff1a<\/p>\n<pre class=\"brush:c\">grep -R -w -l 'boot' \/etc<\/pre>\n<p>\u8fd9\u6837\u4ee5\u6765\u7684\u786e\u65b9\u4fbf\u4e86\u67e5\u770b\uff0c\u4e0d\u8fc7\u7531\u4e8e\u8f93\u51fa\u7ed3\u679c\u5728\u4e00\u4e2a\u5c4f\u5e55\u4e0b\u4e0d\u80fd\u5b8c\u5168\u663e\u793a\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u7528more\u547d\u4ee4\u5206\u5c4f\u67e5\u770b\uff0c\u6216\u8005\u76f4\u63a5\u5c06\u8f93\u51fa\u7ed3\u679c\u91cd\u5b9a\u4f4d\u4e8e\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\uff1a<\/p>\n<pre class=\"brush:c\">grep -R -w -l 'boot' \/etc &gt; .\/output.txt<\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u65b9\u4fbf\u7684\u67e5\u770b\u8f93\u51fa\u7ed3\u679c\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u4e8e\u7ae5\u978b\u95ee\u6211\u5982\u4e0b\u95ee\u9898\uff1a \u5728\/etc\u76ee\u5f55\u4e0b\u5982\u4f55\u67e5\u627e\u5305\u542b&#8217;root&#8217;\u5173\u952e\u5b57\u7684\u6240\u6709\u6587\u4ef6\uff1f  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[153],"tags":[235,236],"class_list":["post-3164","post","type-post","status-publish","format-standard","hentry","category-shell","tag-grep","tag-236"],"views":36733,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=3164"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3164\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3164"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}