{"id":17511,"date":"2024-11-18T15:59:26","date_gmt":"2024-11-18T07:59:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/17511\/"},"modified":"2024-11-18T15:59:26","modified_gmt":"2024-11-18T07:59:26","slug":"%e5%b8%b8%e8%a7%81%e7%9a%84linux%e6%96%87%e4%bb%b6%e6%9f%a5%e6%89%be%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/17511\/","title":{"rendered":"\u5e38\u89c1\u7684Linux\u6587\u4ef6\u67e5\u627e\u6280\u5de7"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/170893569865023.jpg\" class=\"aligncenter\" title=\"\u5e38\u89c1\u7684Linux\u6587\u4ef6\u67e5\u627e\u6280\u5de7\u63d2\u56fe\" alt=\"\u5e38\u89c1\u7684Linux\u6587\u4ef6\u67e5\u627e\u6280\u5de7\u63d2\u56fe\" \/><\/p>\n<p>Linux\u4e2d\u67e5\u627e\u6587\u4ef6\u662f\u6211\u4eec\u5728\u65e5\u5e38\u4f7f\u7528\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u9700\u6c42\uff0c\u65e0\u8bba\u662f\u67e5\u627e\u7279\u5b9a\u6587\u4ef6\u8fd8\u662f\u67e5\u627e\u5305\u542b\u7279\u5b9a\u5185\u5bb9\u7684\u6587\u4ef6\uff0c\u90fd\u9700\u8981\u638c\u63e1\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u672c\u6587\u5c06\u4ecb\u7ecdLinux\u4e2d\u67e5\u627e\u6587\u4ef6\u7684\u5e38\u7528\u65b9\u6cd5\uff0c\u5e76\u9644\u4e0a\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u4f9b\u53c2\u8003\u3002<\/p>\n<h3>1. \u4f7f\u7528find\u547d\u4ee4<\/h3>\n<p>find\u547d\u4ee4\u662fLinux\u7cfb\u7edf\u4e2d\u6700\u5e38\u7528\u7684\u67e5\u627e\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u5176\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>find [path] [options] [expression]<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>[path]\uff1a\u6307\u5b9a\u9700\u8981\u67e5\u627e\u7684\u76ee\u5f55\u8def\u5f84<\/li>\n<li>[options]\uff1a\u67e5\u627e\u9009\u9879\uff0c\u5982-name\u3001-type\u7b49<\/li>\n<li>[expression]\uff1a\u8fc7\u6ee4\u6761\u4ef6\uff0c\u5982\u6587\u4ef6\u540d\u3001\u6587\u4ef6\u7c7b\u578b\u7b49<\/li>\n<\/ul>\n<p>\u5177\u4f53\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<p>\u5728\u5f53\u524d\u76ee\u5f55\u67e5\u627e\u6240\u6709\u4ee5.txt\u4e3a\u6269\u5c55\u540d\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>find . -name \"*.txt\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\n<p>\u5728\/home\u76ee\u5f55\u4e0b\u67e5\u627e\u6240\u6709\u62e5\u6709\u8005\u4e3aroot\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>find \/home -user root<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<h3>2. \u4f7f\u7528grep\u547d\u4ee4<\/h3>\n<p>grep\u547d\u4ee4\u4e3b\u8981\u7528\u4e8e\u5728\u6587\u672c\u6570\u636e\u4e2d\u67e5\u627e\u7279\u5b9a\u5b57\u7b26\u4e32\uff0c\u4e5f\u53ef\u4ee5\u5728\u6587\u4ef6\u4e2d\u67e5\u627e\u5305\u542b\u6307\u5b9a\u5185\u5bb9\u7684\u884c\u3002\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>grep [options] 'pattern' [file]<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>[options]\uff1a\u67e5\u627e\u9009\u9879\uff0c\u5982-r\u9012\u5f52\u67e5\u627e\u3001-i\u5ffd\u7565\u5927\u5c0f\u5199\u7b49<\/li>\n<li>&#8216;pattern&#8217;\uff1a\u9700\u8981\u67e5\u627e\u7684\u5185\u5bb9<\/li>\n<li>[file]\uff1a\u88ab\u67e5\u627e\u7684\u6587\u4ef6<\/li>\n<\/ul>\n<p>\u5177\u4f53\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<p>\u5728\/var\/log\u76ee\u5f55\u4e0b\u67e5\u627e\u5305\u542b\u5173\u952e\u5b57error\u7684\u65e5\u5fd7\u6587\u4ef6\uff1a<\/p>\n<pre>grep -r \"error\" \/var\/log<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\n<p>\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u6587\u4ef6\u4e2d\u5305\u542bhello world\u7684\u884c\uff1a<\/p>\n<pre>grep -r \"hello world\" *<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<h3>3. \u4f7f\u7528locate\u547d\u4ee4<\/h3>\n<p>locate\u547d\u4ee4\u662f\u4e00\u79cd\u5feb\u901f\u67e5\u627e\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u5b83\u901a\u8fc7\u4e00\u4e2a\u6570\u636e\u5e93\u8fdb\u884c\u641c\u7d22\uff0c\u901f\u5ea6\u8f83\u5feb\u3002\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>locate [pattern]<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li>[pattern]\uff1a\u9700\u8981\u67e5\u627e\u7684\u6a21\u5f0f<\/li>\n<\/ul>\n<p>\u5177\u4f53\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<p>\u67e5\u627e\u7cfb\u7edf\u4e2d\u6240\u6709\u5305\u542bexample\u5173\u952e\u5b57\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>locate example<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<h3>4. \u4f7f\u7528ls\u547d\u4ee4\u7ed3\u5408\u901a\u914d\u7b26<\/h3>\n<p>\u9664\u4e86\u4e0a\u8ff0\u547d\u4ee4\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u7ed3\u5408ls\u547d\u4ee4\u548c\u901a\u914d\u7b26\u6765\u67e5\u627e\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u4ee5.log\u4e3a\u7ed3\u5c3e\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>ls *.log<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u662fLinux\u4e2d\u67e5\u627e\u6587\u4ef6\u7684\u5e38\u7528\u65b9\u6cd5\u53ca\u4ee3\u7801\u793a\u4f8b\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u67e5\u627e\u6587\u4ef6\u3002\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\uff0c\u5feb\u901f\u5b9a\u4f4d\u9700\u8981\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5e38\u89c1\u7684Linux\u6587\u4ef6\u67e5\u627e\u6280\u5de7\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u4e2d\u67e5\u627e\u6587\u4ef6\u662f\u6211\u4eec\u5728\u65e5\u5e38\u4f7f\u7528\u4e2d\u7ecf\u5e38\u9047\u5230\u7684\u9700\u6c42\uff0c\u65e0\u8bba\u662f\u67e5\u627e\u7279\u5b9a\u6587\u4ef6\u8fd8\u662f\u67e5\u627e\u5305\u542b\u7279\u5b9a\u5185\u5bb9\u7684\u6587\u4ef6\uff0c\u90fd\u9700\u8981\u638c\u63e1\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u672c\u6587\u5c06\u4ecb\u7ecdLinux\u4e2d\u67e5\u627e\u6587\u4ef6\u7684\u5e38\u7528\u65b9\u6cd5\uff0c\u5e76\u9644\u4e0a\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u4f9b\u53c2\u8003\u3002 1. \u4f7f\u7528find\u547d\u4ee4 find\u547d\u4ee4\u662fLinux\u7cfb\u7edf\u4e2d\u6700\u5e38\u7528\u7684\u67e5\u627e\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u5176\u8bed\u6cd5\u4e3a\uff1a find [path] [options] [expression] \u767b\u5f55\u540e\u590d\u5236 [path]\uff1a\u6307\u5b9a\u9700\u8981\u67e5\u627e\u7684\u76ee\u5f55\u8def\u5f84 [options]\uff1a\u67e5\u627e\u9009\u9879\uff0c\u5982-name\u3001-type\u7b49 [expression]\uff1a\u8fc7\u6ee4\u6761\u4ef6\uff0c\u5982\u6587\u4ef6\u540d\u3001\u6587\u4ef6\u7c7b\u578b\u7b49 \u5177\u4f53\u793a\u4f8b\uff1a \u5728\u5f53\u524d\u76ee\u5f55\u67e5\u627e\u6240\u6709\u4ee5.txt\u4e3a\u6269\u5c55\u540d\u7684\u6587\u4ef6\uff1a find . -name &#8220;*.txt&#8221; \u767b\u5f55\u540e\u590d\u5236 \u5728\/home\u76ee\u5f55\u4e0b\u67e5\u627e\u6240\u6709\u62e5\u6709\u8005\u4e3aroot\u7684\u6587\u4ef6\uff1a find \/home -user root \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528grep\u547d\u4ee4 grep\u547d\u4ee4\u4e3b\u8981\u7528\u4e8e\u5728\u6587\u672c\u6570\u636e\u4e2d\u67e5\u627e\u7279\u5b9a\u5b57\u7b26\u4e32\uff0c\u4e5f\u53ef\u4ee5\u5728\u6587\u4ef6\u4e2d\u67e5\u627e\u5305\u542b\u6307\u5b9a\u5185\u5bb9\u7684\u884c\u3002\u8bed\u6cd5\u4e3a\uff1a grep [options] &#8216;pattern&#8217; [file] \u767b\u5f55\u540e\u590d\u5236 [options]\uff1a\u67e5\u627e\u9009\u9879\uff0c\u5982-r\u9012\u5f52\u67e5\u627e\u3001-i\u5ffd\u7565\u5927\u5c0f\u5199\u7b49 &#8216;pattern&#8217;\uff1a\u9700\u8981\u67e5\u627e\u7684\u5185\u5bb9 [file]\uff1a\u88ab\u67e5\u627e\u7684\u6587\u4ef6 \u5177\u4f53\u793a\u4f8b\uff1a \u5728\/var\/log\u76ee\u5f55\u4e0b\u67e5\u627e\u5305\u542b\u5173\u952e\u5b57error\u7684\u65e5\u5fd7\u6587\u4ef6\uff1a grep -r &#8220;error&#8221; \/var\/log \u767b\u5f55\u540e\u590d\u5236 \u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u6587\u4ef6\u4e2d\u5305\u542bhello world\u7684\u884c\uff1a grep -r &#8220;hello world&#8221; * \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528locate\u547d\u4ee4 locate\u547d\u4ee4\u662f\u4e00\u79cd\u5feb\u901f\u67e5\u627e\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u5b83\u901a\u8fc7\u4e00\u4e2a\u6570\u636e\u5e93\u8fdb\u884c\u641c\u7d22\uff0c\u901f\u5ea6\u8f83\u5feb\u3002\u8bed\u6cd5\u4e3a\uff1a locate [&hellip;]<\/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-17511","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17511","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=17511"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17511\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=17511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=17511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=17511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}