{"id":111,"date":"2022-04-12T15:03:15","date_gmt":"2022-04-12T07:03:15","guid":{"rendered":"https:\/\/www.qiangzhenshuai.com\/?p=111"},"modified":"2025-10-01T16:15:49","modified_gmt":"2025-10-01T08:15:49","slug":"linux-find%e6%9f%a5%e6%89%be","status":"publish","type":"post","link":"https:\/\/www.qiangzhenshuai.com\/?p=111","title":{"rendered":"Linux-find\u67e5\u627e"},"content":{"rendered":"<h1>find \u67e5\u627e\u6587\u4ef6\u6216\u76ee\u5f55<\/h1>\n<h2>find \u8def\u5f84 -\u547d\u4ee4\u53c2\u6570 [\u8f93\u51fa\u5f62\u5f0f]<\/h2>\n<pre>-type\uff1a\u67e5\u627e\u67d0\u4e00\u7c7b\u578b\u7684\u6587\u4ef6\u6216\u76ee\u5f55\r\nd\uff1a\u76ee\u5f55\r\nf\uff1a\u6587\u4ef6\r\nb\uff1a\u5757\u8bbe\u5907\u6587\u4ef6\r\nc\uff1a\u5b57\u7b26\u8bbe\u5907\u6587\u4ef6\r\n-name\uff1a\u6309\u7167\u540d\u5b57\u67e5\u627e\u6587\u4ef6\u6216\u76ee\u5f55\r\n-perm\uff1a\u6309\u7167\u6743\u9650\u67e5\u627e\u6587\u4ef6\u6216\u76ee\u5f55\uff08644\u3001755\uff09\r\n-mtime\uff1a\u6309\u7167\u6587\u4ef6\u66f4\u6539\u7684\u65f6\u95f4\u6765\u67e5\u627e\u6587\u4ef6\u6216\u76ee\u5f55\r\n-n\uff1a\uff08-7\uff097\u5929\u4fee\u6539\u8fc7\u7684\u6587\u4ef6 -\uff1a\u8868\u793a\u4ee5\u5185\r\n+n\uff1a\uff08+7\uff097\u5929\u524d\u4fee\u6539\u8fc7\u7684\u6587\u4ef6 +\uff1a\u8868\u793a\u4ee5\u524d\r\n-nogroup\uff1a\u67e5\u627e\u65e0\u6709\u6548\u6240\u5c5e\u7ec4\u7684\u6587\u4ef6\uff0c\u5373\u8be5\u6587\u4ef6\u6240\u5c5e\u7684\u7ec4\u5728\/etc\/groups\u4e2d\u4e0d\u5b58\u5728\r\n-nouser\uff1a\u67e5\u627e\u65e0\u6709\u6548\u5c5e\u4e3b\u7684\u6587\u4ef6\uff0c\u5373\u8be5\u6587\u4ef6\u7684\u5c5e\u4e3b\u5728\/etc\/passwd\u4e2d\u4e0d\u5b58\u5728\r\n-size\uff1a\u6839\u636e\u6587\u4ef6\u5927\u5c0f\u67e5\u627e\r\nb\uff1a\u4ee3\u8868 512 \u4f4d\u5143\u7ec4\u7684\u533a\u5757\uff08\u5982\u679c\u7528\u6237\u6ca1\u6709\u6307\u5b9a\u540e\u7f00\uff0c\u5219\u9ed8\u8ba4\u4e3a b\uff09\r\nc\uff1a\u8868\u793a\u5b57\u8282\u6570\r\nk\uff1a\u8868\u793a kilo bytes \uff081024\u5b57\u8282\uff09\r\nw\uff1a\u5b57 \uff082\u5b57\u8282\uff09\r\nM\uff1a\u5146\u5b57\u8282\uff081048576\u5b57\u8282\uff09\r\nG\uff1a\u5343\u5146\u5b57\u8282 \uff081073741824\u5b57\u8282\uff09\r\n-follow\uff1a\u5982\u679cfind\u547d\u4ee4\u9047\u5230\u7b26\u53f7\u94fe\u63a5\u6587\u4ef6\uff0c\u5c31\u8ddf\u8e2a\u81f3\u94fe\u63a5\u6240\u6307\u5411\u7684\u6587\u4ef6\r\n-cpio\uff1a\u5bf9\u5339\u914d\u7684\u6587\u4ef6\u4f7f\u7528cpio\u547d\u4ee4\uff0c\u5c06\u8fd9\u4e9b\u6587\u4ef6\u5907\u4efd\u5230\u78c1\u5e26\u8bbe\u5907\u4e2d\r\n-o\uff1a\u662f\u6216\u8005\u7684\u610f\u601d\r\n-a\uff1a\u662f\u800c\u4e14\u7684\u610f\u601d\r\n-not\uff1a\u662f\u76f8\u53cd\u7684\u610f\u601d\r\n-empty\uff1a\u641c\u7d22\u7a7a\u6587\u4ef6\u6216\u7a7a\u76ee\u5f55<\/pre>\n<h2>\u8f93\u51fa\u5f62\u5f0f<\/h2>\n<pre>\u8f93\u51fa\u5f62\u5f0f\u5f88\u591a\uff0c-print,-printf,-exec,-ok,-ls......<\/pre>\n<h2>\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709 go \u6587\u4ef6<\/h2>\n<pre>find . -name \"*.go\"<\/pre>\n<h2>\u67e5\u627e\u6587\u4ef6\u540d\u4e3amemcache.pid\u7684\u6587\u4ef6<\/h2>\n<pre>find \/ -name memcached.pid -print<\/pre>\n<h2>\u5339\u914d\u76f8\u5173\u7684\uff08\u4f7f\u7528\u00a0<code>*<\/code>\u00a0\u4f5c\u4e3a\u901a\u914d\u7b26\uff09<\/h2>\n<p>ll<br \/>\ntotal 0<br \/>\n-rw-r&#8211;r&#8211; 1 root root 0 Sep 30 11:36 123<br \/>\n-rw-r&#8211;r&#8211; 1 root root 0 Sep 30 11:36 123_<br \/>\n-rw-r&#8211;r&#8211; 1 root root 0 Sep 30 11:36 456<br \/>\n-rw-r&#8211;r&#8211; 1 root root 0 Sep 30 11:36 789<\/p>\n<p>[root@web01 ~\/zhangqiang]$ find . -name &#8220;*123*&#8221;<br \/>\n.\/123<br \/>\n.\/123_<\/p>\n<p>find . -name &#8220;123*&#8221;<br \/>\n.\/123<br \/>\n.\/123_<\/p>\n<h4>-name &#8220;\u6587\u4ef6\u540d&#8221;\uff1a\u6309\u6587\u4ef6\u540d\u7cbe\u786e\u5339\u914d\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09\uff0c\u652f\u6301\u901a\u914d\u7b26\u00a0*\uff08\u4efb\u610f\u5b57\u7b26\uff09\u3001?\uff08\u5355\u4e2a\u5b57\u7b26\uff09\u3001[]\uff08\u5b57\u7b26\u8303\u56f4\uff09\u3002<br \/>\n\uff08<strong><code>-iname \"\u6587\u4ef6\u540d\"<\/code><\/strong>\uff1a\u6309\u6587\u4ef6\u540d\u5339\u914d\uff0c<strong>\u5ffd\u7565\u5927\u5c0f\u5199<\/strong>\uff09<\/h4>\n<div>\n<div dir=\"ltr\">\n<div>\n<pre tabindex=\"0\"># \u5728\u5f53\u524d\u76ee\u5f55\u641c\u7d22\u540d\u4e3a \"test.txt\" \u7684\u6587\u4ef6\r\nfind . -name \"test.txt\"\r\n\r\n# \u5728 \/home \u76ee\u5f55\u641c\u7d22\u6240\u6709 .sh \u540e\u7f00\u7684\u6587\u4ef6\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09\r\nfind \/home -name \"*.sh\"\r\n\r\n# \u641c\u7d22\u6587\u4ef6\u540d\u5305\u542b \"log\" \u7684\u6587\u4ef6\uff08\u5982 access.log\u3001error_log\uff09\r\nfind \/var -name \"*log*\"<\/pre>\n<pre tabindex=\"0\"># \u5728 \/tmp \u76ee\u5f55\u641c\u7d22\u6240\u6709\u5b50\u76ee\u5f55\uff08\u4e0d\u5305\u62ec\u6587\u4ef6\uff09\r\nfind \/tmp -type d\r\n\r\n# \u5728\u5f53\u524d\u76ee\u5f55\u641c\u7d22\u6240\u6709\u7b26\u53f7\u94fe\u63a5\u6587\u4ef6\r\nfind . -type l\r\n\r\n# \u641c\u7d22 \/usr\/bin \u4e0b\u6240\u6709\u53ef\u6267\u884c\u6587\u4ef6\uff08\u666e\u901a\u6587\u4ef6\u7c7b\u578b\uff09\r\nfind \/usr\/bin -type f<\/pre>\n<pre tabindex=\"0\"># \u641c\u7d22\u5f53\u524d\u76ee\u5f55\u4e0b\u5927\u5c0f\u8d85\u8fc7 100MB \u7684\u6587\u4ef6\r\nfind . -type f -size +100M\r\n\r\n# \u641c\u7d22 \/var\/log \u4e0b\u5927\u5c0f\u5c0f\u4e8e 1KB \u7684\u65e5\u5fd7\u6587\u4ef6\r\nfind \/var\/log -type f -name \"*.log\" -size -1k\r\n\r\n# \u641c\u7d22\u5927\u5c0f\u6b63\u597d\u4e3a 512\u5b57\u8282\uff081\u5757\uff09\u7684\u6587\u4ef6\r\nfind . -type f -size 1b<\/pre>\n<pre tabindex=\"0\"># \u641c\u7d22\u5f53\u524d\u76ee\u5f55\u4e0b 7\u5929\u5185\u4fee\u6539\u8fc7\u7684 .txt \u6587\u4ef6\r\nfind . -type f -name \"*.txt\" -mtime -7\r\n\r\n# \u641c\u7d22 \/var\/log \u4e0b 30\u5929\u524d\uff08\u8d85\u8fc730\u5929\uff09\u672a\u4fee\u6539\u7684\u65e5\u5fd7\u6587\u4ef6\uff08\u53ef\u6e05\u7406\uff09\r\nfind \/var\/log -type f -name \"*.log\" -mtime +30\r\n\r\n# \u641c\u7d22 2\u5929\u524d\uff08\u6b63\u597d2\u5929\uff09\u8bbf\u95ee\u8fc7\u7684\u6587\u4ef6\r\nfind . -type f -atime 2<\/pre>\n<pre tabindex=\"0\"># \u641c\u7d22\u5f53\u524d\u76ee\u5f55\u4e0b\u6743\u9650\u4e3a 755 \u7684\u6587\u4ef6\uff08\u7528\u6237\u53ef\u8bfb\u53ef\u5199\u53ef\u6267\u884c\uff0c\u7ec4\u548c\u5176\u4ed6\u53ef\u8bfb\u53ef\u6267\u884c\uff09\r\nfind . -type f -perm 755\r\n\r\n# \u641c\u7d22\u6743\u9650\u4e3a 600 \u7684\u6587\u4ef6\uff08\u4ec5\u6240\u6709\u8005\u53ef\u8bfb\u53ef\u5199\uff09\r\nfind . -type f -perm 600<\/pre>\n<pre class=\"container-_HmLba language-bash\" tabindex=\"0\"># \u641c\u7d22\u5176\u4ed6\u7528\u6237\u6709\u5199\u6743\u9650\u7684\u6587\u4ef6\uff08\u6743\u9650\u5305\u542b 002\uff09\r\nfind . -type f -perm -002# \u5176\u4ed6\u7528\u6237\u5199\u6743\u9650\u4f4d\u4e3a<\/pre>\n<h2 class=\"header-vfC6AV auto-hide-last-sibling-br\">\u903b\u8f91\u7ec4\u5408\u6761\u4ef6\uff08\u4e0e \/ \u6216 \/ \u975e\uff09<\/h2>\n<p>\u591a\u4e2a\u6761\u4ef6\u53ef\u901a\u8fc7\u903b\u8f91\u8fd0\u7b97\u7b26\u7ec4\u5408\uff1a<\/p>\n<div>-a\uff1a\u903b\u8f91 \u201c\u4e0e\u201d\uff08\u9ed8\u8ba4\uff0c\u53ef\u7701\u7565\uff09\uff0c\u5373\u540c\u65f6\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\uff1b<\/div>\n<div>-o\uff1a\u903b\u8f91 \u201c\u6216\u201d\uff0c\u6ee1\u8db3\u4efb\u4e00\u6761\u4ef6\u5373\u53ef\uff1b<\/div>\n<div>!\u00a0\u6216\u00a0-not\uff1a\u903b\u8f91 \u201c\u975e\u201d\uff0c\u6392\u9664\u6ee1\u8db3\u6761\u4ef6\u7684\u7ed3\u679c\u3002<\/div>\n<div>\n<div dir=\"ltr\">\n<div>\n<pre tabindex=\"0\"># \u641c\u7d22 7\u5929\u5185\u4fee\u6539\u8fc7\u7684 .sh \u6587\u4ef6\uff08\u4e14\u5173\u7cfb\uff0c-a \u53ef\u7701\u7565\uff09\r\nfind . -type f -name \"*.sh\" -mtime -7\r\n\r\n# \u641c\u7d22 .txt \u6216 .md \u540e\u7f00\u7684\u6587\u4ef6\uff08\u6216\u5173\u7cfb\uff09\r\nfind . -type f -name \"*.txt\" -o -name \"*.md\"\r\n\r\n# \u641c\u7d22\u4e0d\u662f root \u6240\u6709\u7684 .log \u6587\u4ef6\uff08\u975e\u5173\u7cfb\uff09\r\nfind \/var\/log -type f -name \"*.log\" ! -user root<\/pre>\n<h2>\u6267\u884c\u547d\u4ee4\uff08-exec\uff0c\u6700\u5f3a\u5927\uff09<\/h2>\n<div>\u8bed\u6cd5\uff1afind &#8230; -exec \u547d\u4ee4 {} \\;<\/div>\n<p>{}\uff1a\u4ee3\u8868\u627e\u5230\u7684\u6bcf\u4e2a\u6587\u4ef6 \/ \u76ee\u5f55\u7684\u8def\u5f84\uff1b<\/p>\n<p>\\;\uff1a\u8868\u793a\u547d\u4ee4\u7ed3\u675f\uff08\u5fc5\u987b\u8f6c\u4e49\uff0c\u907f\u514d\u88ab shell \u89e3\u6790\uff09\u3002<\/p>\n<div>\n<div dir=\"ltr\">\n<div>\n<div>\n<div>\n<div tabindex=\"0\" aria-describedby=\"r9wnxdl\" data-popupid=\"r9wnxdl\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"># \u641c\u7d22\u6240\u6709 .txt \u6587\u4ef6\uff0c\u5e76\u663e\u793a\u5176\u8be6\u7ec6\u4fe1\u606f\uff08\u7b49\u4ef7\u4e8e\u5bf9\u6bcf\u4e2a\u6587\u4ef6\u6267\u884c ls -l\uff09\r\nfind . -type f -name \"*.txt\" -exec ls -l {} \\;\r\n\r\n# \u641c\u7d22 30\u5929\u524d\u7684 .log \u6587\u4ef6\uff0c\u5e76\u5220\u9664\uff08\u8c28\u614e\u4f7f\u7528\uff01\uff09\r\nfind \/var\/log -type f -name \"*.log\" -mtime +30 -exec rm -f {} \\;\r\n\r\n# \u641c\u7d22\u6240\u6709 .sh \u6587\u4ef6\uff0c\u590d\u5236\u5230 \/tmp\/scripts \u76ee\u5f55\r\nmkdir -p \/tmp\/scripts\r\nfind . -type f -name \"*.sh\" -exec cp {} \/tmp\/scripts\/ \\;<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>find \u67e5\u627e\u6587\u4ef6\u6216\u76ee\u5f55 find \u8def\u5f84 -\u547d\u4ee4\u53c2\u6570 [\u8f93\u51fa\u5f62\u5f0f] -type\uff1a\u67e5\u627e\u67d0\u4e00\u7c7b\u578b\u7684\u6587\u4ef6\u6216\u76ee\u5f55 d\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[5],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/111"}],"collection":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=111"}],"version-history":[{"count":10,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":1531,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/111\/revisions\/1531"}],"wp:attachment":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}