{"id":484,"date":"2024-04-12T10:33:54","date_gmt":"2024-04-12T02:33:54","guid":{"rendered":"http:\/\/blue.yn.cn\/?p=484"},"modified":"2024-12-08T16:15:02","modified_gmt":"2024-12-08T08:15:02","slug":"%e6%96%87%e4%bb%b6%e6%9f%a5%e6%89%be","status":"publish","type":"post","link":"http:\/\/blue.yn.cn\/?p=484","title":{"rendered":"\u6587\u4ef6\u67e5\u627e"},"content":{"rendered":"<h3>\u6587\u4ef6\u67e5\u627e\u6982\u8ff0<\/h3>\n<h4>\u4e3a\u4ec0\u4e48\u9700\u8981\u67e5\u627e<\/h4>\n<ul>\n<li>\u5f88\u591a\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u4f1a\u5fd8\u4e86\u6587\u4ef6\u6240\u5728\u7684\u4f4d\u7f6e\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u901a\u8fc7<code>find<\/code>\u6765\u67e5\u627e<\/li>\n<li>\u6709\u65f6\u5019\u9700\u8981\u901a\u8fc7\u5185\u5bb9\u67e5\u627e\u5230\u5bf9\u5e94\u7684\u6587\u4ef6\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u901a\u8fc7<code>find<\/code>\u6765\u67e5\u627e<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">find \/etc -type f | xargs grep &quot;blue.yn.cn&quot;\n\/etc\/sysconfig\/network-scripts\/ifcfg-eth0:IPADDR=blue.yn.cn<\/code><\/pre>\n<h4>\u4e3a\u4ec0\u4e48\u662ffind<\/h4>\n<ul>\n<li>\u56e0\u4e3a<code>find<\/code>\u547d\u4ee4\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u6761\u4ef6\u6765\u8fdb\u884c\u67e5\u627e\u6587\u4ef6<\/li>\n<li>\u6bd4\u5982\uff1a\n<ul>\n<li>\u6587\u4ef6\u540d\u79f0<\/li>\n<li>\u6587\u4ef6\u5927\u5c0f<\/li>\n<li>\u6587\u4ef6\u65f6\u95f4<\/li>\n<li>\u6587\u4ef6\u5c5e\u7ec4<\/li>\n<li>\u6743\u9650\u7b49\u7b49<\/li>\n<\/ul>\n<\/li>\n<li>\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0a\u51e0\u79cd\u65b9\u5f0f\u67e5\u627e\u6587\u4ef6\uff0c\u4ece\u800c\u5b9e\u73b0\u7cbe\u51c6\u5b9a\u4f4d<\/li>\n<\/ul>\n<h4>find\u547d\u4ee4\u8bed\u6cd5<\/h4>\n<table>\n<thead>\n<tr>\n<th>\u547d\u4ee4<\/th>\n<th>\u8def\u5f84<\/th>\n<th>\u9009\u9879<\/th>\n<th>\u8868\u8fbe\u5f0f<\/th>\n<th>\u52a8\u4f5c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>find<\/td>\n<td>[path...]<\/td>\n<td>[option]<\/td>\n<td>[expression]<\/td>\n<td>[action]<\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u627e<\/td>\n<td>\u5730\u533a<\/td>\n<td>\u59b9\u7eb8<\/td>\n<td>18-25\u5c81<\/td>\n<td>\uff1f\uff1f\uff1f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>find\u67e5\u627e\u793a\u4f8b<\/h3>\n<h4>find\u57fa\u4e8e\u540d\u79f0\u67e5\u627e<\/h4>\n<pre><code class=\"language-bash\"># \u521b\u5efa\u6587\u4ef6\ntouch \/etc\/sysconfig\/network-scripts\/{ifcfg-eth1,IFCFG-ETH1}\n# \u67e5\u627e\/etc\u76ee\u5f55\u4e0b\u5305\u542bifcfg-eht1\u540d\u79f0\u7684\u6587\u4ef6\nfind \/etc\/ -name &quot;ifcfg-eth1&quot;\n# -i \u5ffd\u7565\u5927\u5c0f\u5199\nfind \/etc\/ -iname &quot;ifcfg-eth1&quot;\n# \u67e5\u627e\/etc\u76ee\u5f55\u4e0b\u5305\u542bifcfg-eth\u540d\u79f0\u6240\u6709\u6587\u4ef6\nfind \/etc\/ -name &quot;ifcfg-eth*&quot;\nfind \/etc\/ -iname &quot;ifcfg-eth*&quot;<\/code><\/pre>\n<h4>find\u57fa\u4e8e\u5927\u5c0f\u67e5\u627e<\/h4>\n<pre><code class=\"language-bash\"># \u67e5\u627e\u5927\u4e8e5M\u7684\u6587\u4ef6\nfind \/etc -size +5M\n# \u67e5\u627e\u7b49\u4e8e5M\u7684\u6587\u4ef6\nfind \/etc -size 5M\n# \u67e5\u627e\u5c0f\u4e8e5M\u7684\u6587\u4ef6\nfind \/etc -size -5M\n# \u67e5\u627e\u5927\u4e8e5M\u5c0f\u4e8e7M\u7684\u6587\u4ef6\ndd if=\/dev\/zero of=\/root\/big bs=6M count=1\nfind \/etc -size +5M -a -size -7M | xargs ls -lh\n-rw-r--r-- 1 root root 6.0M 4\u6708  12 11:21 \/root\/big<\/code><\/pre>\n<h4>\u57fa\u4e8e\u7c7b\u578b\u67e5\u627e<\/h4>\n<pre><code class=\"language-bash\"># f \u6587\u4ef6\nfind \/dev -type f\n# d \u76ee\u5f55\nfind \/dev -type d\n# l \u94fe\u63a5\nfind \/dev -type l\n# b \u5757\u8bbe\u5907\nfind \/dev -type b\n# c \u5b57\u7b26\u8bbe\u5907\nfind \/dev -type c\n# s \u5957\u63a5\u5b57\nfind \/dev -type s\n# p \u7ba1\u9053\u6587\u4ef6\nfind \/dev -type p<\/code><\/pre>\n<h4>find\u57fa\u4e8e\u65f6\u95f4\u67e5\u627e<\/h4>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/04\/image-1712893025216.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-bash\"># \u521b\u5efa\u6d4b\u8bd5\u6587\u4ef6\nfor i in {01..10};do date -s 202404$i &amp;&amp; touch file-$i;done\n# \u67e5\u627e7\u5929\u4ee5\u524d\u7684\u6587\u4ef6\nfind .\/ -iname &quot;file-*&quot; -mtime +7\n# \u67e5\u627e\u7b2c7\u5929\u7684\u6587\u4ef6\nfind .\/ -iname &quot;file-*&quot; -mtime 7\n# \u67e5\u627e\u6700\u8fd17\u5929\u7684\u6587\u4ef6\nfind .\/ -iname &quot;file-*&quot; -mtime -7\n# \u67e5\u627e\/var\/log\u4e0b\u6240\u6709\u4ee5.log\u7ed3\u5c3e\u7684\u6587\u4ef6\uff0c\u5e76\u4fdd\u7559\u6700\u8fd17\u5929\u7684log\u6587\u4ef6\nfind \/var\/log -type f -name &quot;*.log&quot; -mtime +7 -delete\n# \u67e5\u627e\u6700\u8fd1120\u5206\u949f\u5185\u53d1\u751f\u4fee\u6539\u7684\u6587\u4ef6\nfind .\/ type f -mmin -120\n# \u67e5\u627e\u7cfb\u7edf\u6709\u54ea\u4e9b\u547d\u4ee4\u5728\u6700\u8fd1\u591a\u957f\u65f6\u95f4\u5185\uff0c\u53d1\u751f\u8fc7\u53d8\u5316\nfind \/bin\/ \/sbin\/ -type f -mmin -5<\/code><\/pre>\n<h4>find\u57fa\u4e8e\u7528\u6237\u67e5\u627e<\/h4>\n<pre><code class=\"language-bash\"># \u67e5\u627e\u5c5e\u4e3b\u662fjack\nfind \/home -user jack\n# \u67e5\u627e\u5c5e\u7ec4\u662fadmin\nfind \/home -group admin\n# \u67e5\u627e\u5c5e\u4e3b\u662fjack\uff0c\u5c5e\u7ec4\u662fadmin\nfind \/home -user jack -group admin\n# \u67e5\u627e\u5c5e\u4e3b\u662fjack\uff0c\u5e76\u4e14\u5c5e\u7ec4\u662fadmin\nfind \/home -user jack -a -group admin\n# \u67e5\u627e\u5c5e\u4e3b\u662fjack\uff0c\u6216\u8005\u5c5e\u7ec4\u662fadmin\nfind \/home -user jack -o -group admin\n# \u67e5\u627e\u6ca1\u6709\u5c5e\u4e3b\nfind \/home -nouser\n# \u67e5\u627e\u6ca1\u6709\u5c5e\u7ec4\nfind \/home -nogroup\n# \u67e5\u627e\u6ca1\u6709\u5c5e\u4e3b\u6216\u5c5e\u7ec4\nfind \/home -nouser -o -nogroup<\/code><\/pre>\n<h4>find\u57fa\u4e8e\u6743\u9650\u67e5\u627e<\/h4>\n<ul>\n<li><code>-perm [\/|-]MODE<\/code>\n<ul>\n<li><code>MODE<\/code>:\u7cbe\u786e\u6743\u9650\u5339\u914d<\/li>\n<li><code>-MODE<\/code>:\u6bcf\u4e00\u7c7b\u5bf9\u8c61\u90fd\u5fc5\u987b\u540c\u65f6\u62e5\u6709\u6307\u5b9a\u7684\u6743\u9650\uff08\u5e76\u4e14\u7684\u5173\u7cfb\uff09<\/li>\n<li><code>\/MODE<\/code>:\u4efb\u4f55\u4e00\u7c7b\uff08UGO\uff09\u53ea\u8981\u6709\u4e00\u4f4d\u5339\u914d\u5373\u53ef\uff08\u6216\u8005\u7684\u5173\u7cfb\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-bash\"># \u7cbe\u786e\nfind \/root -type f -perm 644 -ls\n# -\u5305\u542b\uff08u\u6db5\u76d66\uff0c\u5e76\u4e14g\u6db5\u76d64\uff0c\u5e76\u4e14o\u6db5\u76d64\uff09\nfind \/root -type f -perm -644 -ls\n# \/\u6216\u8005\uff08u\u4e3a6\uff0c\u6216\u8005g\u4e3a4\uff0c\u6216\u8005o\u4e3a0\uff09\nfind \/root -type f -perm \/640 -ls\n# \u7279\u4fd7\u6743\u9650\nfind \/usr\/bin\/ \/usr\/sbin\/ -type f -perm -4000 -ls\nfind \/usr\/bin\/ \/usr\/sbin\/ -type f -perm -2000 -ls\nfind \/usr\/bin\/ \/usr\/sbin\/ -type f -perm -1000 -ls<\/code><\/pre>\n<h3>find\u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u7b26\u53f7<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>-a<\/td>\n<td>\u4e0e\uff08\u5e76\u4e14\uff09<\/td>\n<\/tr>\n<tr>\n<td>-o<\/td>\n<td>\u6216\uff08\u6216\u8005\uff09<\/td>\n<\/tr>\n<tr>\n<td>-not\/!<\/td>\n<td>\u975e\uff08\u53d6\u53cd\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-bash\"># \u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u5c5e\u4e3b\u4e0d\u662froot\u7684\u6240\u6709\u6587\u4ef6\nfind . -not -user root\nfind . ! -user root\n# \u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u5c5e\u4e3b\u5c5e\u4e8ehdfs\uff0c\u5e76\u4e14\u5927\u5c0f\u5927\u4e8e1k\u7684\u6587\u4ef6\nfind . -type f -user hdfs -a -size +1k\n# \u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u5c5e\u4e3b\u4e3aroot\u6216\u8005\u4ee5xml\u7ed3\u5c3e\u7684\u666e\u901a\u6587\u4ef6\nfind . -type f -a \\( -user root -o -name &#039;*.xml&#039; \\)<\/code><\/pre>\n<h3>find\u52a8\u4f5c\u5904\u7406<\/h3>\n<ul>\n<li>\u67e5\u627e\u5230\u4e00\u4e2a\u6587\u4ef6\u540e\uff0c\u9700\u8981\u5bf9\u6587\u4ef6\u8fdb\u884c\u5982\u4f55\u5904\u7406\uff0c<code>find<\/code>\u7684\u9ed8\u8ba4\u52a8\u4f5c\u662f<code>-print<\/code><\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>\u52a8\u4f5c<\/th>\n<th>\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>-print<\/td>\n<td>\u6253\u5370\u67e5\u627e\u5230\u7684\u5185\u5bb9\uff08\u9ed8\u8ba4\uff09<\/td>\n<\/tr>\n<tr>\n<td>-ls<\/td>\n<td>\u4ee5\u957f\u683c\u5f0f\u663e\u793a\u7684\u65b9\u5f0f\u6253\u5370\u67e5\u627e\u5230\u7684\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>-delete<\/td>\n<td>\u5220\u9664\u67e5\u627e\u5230\u7684\u6587\u4ef6\uff08\u4ec5\u80fd\u5220\u9664\u7a7a\u76ee\u5f55\uff09<\/td>\n<\/tr>\n<tr>\n<td>-ok<\/td>\n<td>\u540e\u9762\u8ddf\u81ea\u5b9a\u4e49shell\u547d\u4ee4\uff08\u4f1a\u63d0\u793a\u662f\u5426\u64cd\u4f5c\uff09<\/td>\n<\/tr>\n<tr>\n<td>-exec<\/td>\n<td>\u540e\u9762\u8ddf\u81ea\u5b9a\u4e49shell\u547d\u4ee4 \uff08\u6807\u51c6\u5199\u6cd5 -exec \\;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>find\u7ed3\u5408exec<\/h4>\n<ul>\n<li>\u4f7f\u7528<code>exec<\/code>\u5b9e\u73b0\u6587\u4ef6\u62f7\u8d1d\u548c\u5220\u9664<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">find \/etc -name &quot;ifcfg*&quot; -exec cp -rvf{} \/tmp \\;\nfind \/etc -name &quot;ifcfg*&quot; -exec rm -f{}  \\;<\/code><\/pre>\n<h4>find\u7ed3\u5408xargs<\/h4>\n<ul>\n<li><code>xargs<\/code>\u5c06\u524d\u8005\u547d\u4ee4\u67e5\u627e\u5230\u7684\u6587\u4ef6\u4e00\u4e2a\u6574\u4f53\u4f20\u9012\u540e\u8005\u547d\u4ee4\u7684\u8f93\u5165\uff0c\u6240\u4ee5\u5176\u5904\u7406\u6027\u80fd\u6781\u9ad8<\/li>\n<li><code>exec<\/code>\u662f\u5c06\u6587\u4ef6\u4e00\u4e2a\u4e00\u4e2a\u7684\u5904\u7406\uff0c\u6240\u4ee5\u5904\u7406\u6027\u80fd\u6781\u4f4e<\/li>\n<\/ul>\n<pre><code class=\"language-bash\"># \u5220\u9664\u6587\u4ef6\uff0c\u6027\u80fd\u5bf9\u6bd4\ntouch file-{1..10000}\nfind .\/ -type -f -name &quot;file-*&quot; -exec rm -f {} \\;\nfind .\/ -type -f -name &quot;file-*&quot; | xargs rm -f\n# \u6587\u4ef6\u62f7\u8d1d\nfind \/usr\/sbin\/ -type f -perm -4000 | xargs -I {} cp -rv {} \/tmp<\/code><\/pre>\n<h4>find\u7ed3\u5408grep<\/h4>\n<ul>\n<li>\u5f53\u5fd8\u8bb0\u91cd\u8981\u914d\u7f6e\u6587\u4ef6\u5b58\u50a8\u8def\u5f84\u65f6\uff0c\u53ef\u901a\u8fc7\u6536\u7d22\u5173\u952e\u5b57\u83b7\u53d6\u6587\u4ef6\u5176\u8def\u5f84\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">find \/etc -type f | xargs grep &quot;blue.yn.cn&quot;\nfind \/etc -type f | xargs grep -r &quot;blue.yn.cn&quot;\nfind \/etc -type f | xargs grep -R &quot;blue.yn.cn&quot;\n\/etc\/sysconfig\/network-scripts\/ifcfg-eth0:IPADDR=blue.yn.cn<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u4ef6\u67e5\u627e\u6982\u8ff0 \u4e3a\u4ec0\u4e48\u9700\u8981\u67e5\u627e \u5f88\u591a\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u4f1a\u5fd8\u4e86\u6587\u4ef6\u6240\u5728\u7684\u4f4d\u7f6e\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u901a\u8fc7find\u6765\u67e5\u627e \u6709\u65f6\u5019\u9700\u8981\u901a&#8230; &raquo; <a class=\"read-more-link\" href=\"http:\/\/blue.yn.cn\/?p=484\">\u9605\u8bfb\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-484","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=484"}],"version-history":[{"count":8,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/484\/revisions"}],"predecessor-version":[{"id":1820,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/484\/revisions\/1820"}],"wp:attachment":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}