{"id":178,"date":"2021-05-18T21:21:29","date_gmt":"2021-05-18T13:21:29","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=178"},"modified":"2022-01-12T21:26:15","modified_gmt":"2022-01-12T13:26:15","slug":"8-linux%e5%9b%9b%e5%89%91%e5%ae%a2%e4%b9%8bfind","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=178","title":{"rendered":"8.linux\u56db\u5251\u5ba2\u4e4bfind"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.find\u67e5\u627e\u5e94\u7528\u573a\u666f<\/h2>\n\n\n\n<p>1.\u5fd8\u8bb0\u6587\u4ef6\u7684\u8def\u5f84;<br>2.\u8bb0\u5f97\u6587\u4ef6\u5185\u5bb9,\u4f46\u4e0d\u77e5\u9053\u662f\u54ea\u4e2a\u6587\u4ef6;<\/p>\n\n\n\n<p><strong><em>find \u547d\u4ee4\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b<\/em><\/strong><\/p>\n\n\n\n<p>\u547d\u4ee4--&gt;\u8def\u5f84--&gt;\u9009\u9879--&gt;\u8868\u8fbe\u5f0f--&gt;\u52a8\u4f5c<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_1\">2.find\u67e5\u627e\u793a\u4f8b<\/h2>\n\n\n\n<p><strong><em>\u4ee5\u4e0b\u5217\u51fa\u6240\u6709find\u5e38\u7528\u7684\u9009\u9879<\/em><\/strong><\/p>\n\n\n\n<p>1.\u57fa\u4e8e\u7c7b\u578b;f d s c b l<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># f \u6587\u4ef6\n&#91;root@web01 ~]# find \/dev -type f\n# d \u76ee\u5f55\n&#91;root@web01 ~]# find \/dev -type d\n# l \u94fe\u63a5\n&#91;root@web01 ~]# find \/dev -type l\n# b \u5757\u8bbe\u5907\n&#91;root@web01 ~]# find \/dev -type b\n# c \u5b57\u7b26\u8bbe\u5907\n&#91;root@web01 ~]# find \/dev -type c\n# s \u5957\u63a5\u5b57\n&#91;root@web01 ~]# find \/dev -type s\n# p \u7ba1\u9053\u6587\u4ef6\n&#91;root@web01 ~]# find \/dev -type p<\/code><\/pre>\n\n\n\n<p><em>2.\u57fa\u4e8e\u540d\u79f0<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u67e5\u627e\/etc\u76ee\u5f55\u4e0b\u5305\u542bifcfg-eth0\u540d\u79f0\u7684\u6587\u4ef6\n&#91;root@web01 ~]# find \/etc -name \"ifcfg-eth1\"\n#2.-i \u5ffd\u7565\u5927\u5c0f\u5199\n&#91;root@web01 ~]# find \/etc -iname \"ifcfg-eth1\"\n#\u67e5\u627e\/etc\u76ee\u5f55\u4e0b\u5305\u542bifcfg-eth\u540d\u79f0\u6240\u6709\u6587\u4ef6\n&#91;root@web01 ~]# find \/etc\/ -name \"ifcfg-eth*\"\n&#91;root@web01 ~]# find \/etc -iname \"ifcfg-eth*\"<\/code><\/pre>\n\n\n\n<p><em>3.\u57fa\u4e8e\u5927\u5c0f<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u67e5\u627e\u5927\u4e8e5M\u7684\u6587\u4ef6\n&#91;root@web01 ~]# find \/etc -size +5M\n#2.\u67e5\u627e\u7b49\u4e8e5M\u7684\u6587\u4ef6\n&#91;root@web01 ~]# find \/etc -size 5M\n#3.\u67e5\u627e\u5c0f\u4e8e5M\u7684\u6587\u4ef6\n&#91;root@web01 ~]# find \/etc -size -5M <\/code><\/pre>\n\n\n\n<p><em>4.find\u65f6\u95f4\u67e5\u627e<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u521b\u5efa\u6d4b\u8bd5\u6587\u4ef6\n&#91;root@web01 ~]# for i in {01..28};do date -s  202104$i &amp;&amp; touch file-$i;done\n#2.\u67e5\u627e7\u5929\u4ee5\u524d\u7684\u6587\u4ef6(\u4e0d\u4f1a\u6253\u5370\u5f53\u5929\u7684\u6587\u4ef6)\n&#91;root@web01 ~]# find .\/ -iname \"file-*\" -mtime +7\n#3.\u67e5\u627e\u6700\u8fd17\u5929\u7684\u6587\u4ef6\uff0c\u4e0d\u5efa\u8bae\u4f7f\u7528(\u4f1a\u6253\u5370\u5f53\u5929\u7684\u6587\u4ef6)\n&#91;root@web01 ~]# find .\/ -iname \"file-*\" -mtime -7\n#4.\u67e5\u627e\u7b2c7\u5929\u6587\u4ef6(\u4e0d\u4f1a\u6253\u5370\u5f53\u5929\u7684\u6587\u4ef6)\n&#91;root@web01 ~]# find .\/ -iname \"file-*\" -mtime 7\n#5.\u672c\u5730\u6587\u4ef6\u4fdd\u7559\u6700\u8fd17\u5929\u7684\u5907\u4efd\u6587\u4ef6, \u5907\u4efd\u670d\u52a1\u5668\u4fdd\u75593\u4e2a\u6708\u7684\u5907\u4efd\u6587\u4ef6(\u5b9e\u9645\u4f7f\u7528\u65b9\u6848)\nfind \/backup\/ -iname \"*.bak\" -mtime +7 -delete\nfind \/backup\/ -iname \"*.bak\" -mtime +90 -delete<\/code><\/pre>\n\n\n\n<p><em>5.\u57fa\u4e8e\u7528\u6237\u67e5\u627e<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u67e5\u627e\u5c5e\u4e3b\u662fjack\n&#91;root@web01 ~]# find \/home -user jack\n#\u67e5\u627e\u5c5e\u7ec4\u662fadmin\n&#91;root@web01 ~]# find \/home -group admin\n#\u67e5\u627e\u5c5e\u4e3b\u662fjack, \u5c5e\u7ec4\u662fadmin\n&#91;root@web01 ~]# find \/home -user jack -group admin\n#\u67e5\u627e\u5c5e\u4e3b\u662fjack, \u5e76\u4e14\u5c5e\u7ec4\u662fadmin\n&#91;root@web01 ~]# find \/home -user jack -a -group admin\n#\u67e5\u627e\u5c5e\u4e3b\u662fjack, \u6216\u8005\u5c5e\u7ec4\u662fadmin\n&#91;root@web01 ~]# find \/home -user jack -o -group admin\n#\u67e5\u627e\u6ca1\u6709\u5c5e\u4e3b\n&#91;root@web01 ~]# find \/home -nouser\n#\u67e5\u627e\u6ca1\u6709\u5c5e\u7ec4\n&#91;root@web01 ~]# find \/home -nogroup\n#\u67e5\u627e\u6ca1\u6709\u5c5e\u4e3b\u6216\u5c5e\u7ec4\n&#91;root@web01 ~]# find \/home -nouser -o -nogroup\n<\/code><\/pre>\n\n\n\n<p><strong><em>6.find\u52a8\u4f5c\u5904\u7406\uff0c\u6bd4\u5982\u67e5\u627e\u5230\u4e00\u4e2a\u6587\u4ef6\u540e\uff0c\u9700\u8981\u5bf9\u6587\u4ef6\u8fdb\u884c\u5982\u4f55\u5904\u7406, find\u7684\u9ed8\u8ba4\u52a8\u4f5c\u662f -print<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-ok: \u63d0\u793a\n-exec: \u9010\u4e2a\u6267\u884c;   \u4f7f\u7528xargs \u66ff\u4ee3; \u5c06\u6240\u6709\u7684\u7ed3\u679c\u6253\u5305\u4e00\u8d77\u76f4\u63a5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012;\n-print: \u9ed8\u8ba4;\n-ls:   \u53ef\u4ee5\u4f7f\u7528xargs ls -l \u66ff\u4ee3\n\n\u590d\u5236;\n&#91;root@web01 ~]# find -type f -name \"file*\" -mtime +20 -exec cp -rv {} \/tmp \\;\n\n\u7ed3\u5408xargs\u590d\u5236\uff1b\n&#91;root@web01 ~]# find -type f -name \"file*\" -mtime +15 | xargs cp -rvt \/tmp\/\n\u5220\u9664;\n&#91;root@web01 ~]# touch {1..10000}\t\n&#91;root@web01 ~]# time find .\/ -type f ! -name \".bash*\" -exec rm -f {} \\;\n\n&#91;root@web01 ~]# time find .\/ -type f ! -name \".bash*\" | xargs rm -f \n\n\u8fc7\u6ee4;\n&#91;root@web01 ~]# find .\/ -type f | xargs grep \"web01\" --color\n.\/6:\tweb01\nfind\u7ed3\u5408sed\u5b9e\u73b0\u6279\u91cf\u4fee\u6539\u6587\u4ef6\u540d\u79f0:\ntouch file-{1..10}\nfind .\/ -type f -name \"file*\" | sed -r 's#(.*)-(.*)# mv \\1-\\2 test-\\2#g' |bash<\/code><\/pre>\n\n\n\n<p><em>7.find\u903b\u8f91\u8fd0\u7b97\u7b26<\/em><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u7b26\u53f7<\/th><th>\u4f5c\u7528<\/th><\/tr><\/thead><tbody><tr><td>-a<\/td><td>\u4e0e<\/td><\/tr><tr><td>-o<\/td><td>\u6216<\/td><\/tr><tr><td>-not|!<\/td><td>\u975e<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u5c5e\u4e3b\u4e0d\u662fhdfs\u7684\u6240\u6709\u6587\u4ef6\n&#91;root@web01 ~]# find . -not -user hdfs \n&#91;root@web01 ~]# find . ! -user hdfs\n        \n#2.\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u5c5e\u4e3b\u5c5e\u4e8ehdfs\uff0c\u4e14\u5927\u5c0f\u5927\u4e8e300\u5b57\u8282\u7684\u6587\u4ef6\n&#91;root@web01 ~]# find . -type f -a -user hdfs -a -size +300c\n            \n#3.\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u5c5e\u4e3b\u4e3ahdfs\u6216\u8005\u4ee5xml\u7ed3\u5c3e\u7684\u666e\u901a\u6587\u4ef6\n&#91;root@web01 ~]# find . -type f -a \\( -user hdfs -o -name '*.xml' \\)\n#4.\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u540d\u5b57\u4ee5file\u7ed3\u5c3e\u6216\u4ee5check\u7ed3\u5c3e\u5e76\u5220\u9664\uff0c\u4f46\u662f\u6392\u9664\u4ee51.file\u6216\u4ee51.check\u7ed3\u5c3e\u7684\u6587\u4ef6\nfind . -type f \\( -name '*.file' -o -name '*.check' \\) ! \\( -name \"*1.file\" -o -name \"*1.check\" \\) -exec rm -vf {}  \\; <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,15],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/178"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=178"}],"version-history":[{"count":1,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":414,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/178\/revisions\/414"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}