{"id":2510,"date":"2015-11-07T15:33:12","date_gmt":"2015-11-07T07:33:12","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2510"},"modified":"2015-11-07T15:33:12","modified_gmt":"2015-11-07T07:33:12","slug":"linux%e4%b8%8b%e7%94%a8find%e5%91%bd%e4%bb%a4%e4%b8%80%e6%ac%a1%e6%9f%a5%e6%89%be%e5%a4%9a%e7%a7%8d%e7%b1%bb%e5%9e%8b%e7%9a%84%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2510.html","title":{"rendered":"Linux\u4e0b\u7528find\u547d\u4ee4\u4e00\u6b21\u67e5\u627e\u591a\u79cd\u7c7b\u578b\u7684\u6587\u4ef6"},"content":{"rendered":"<p>=Start=<\/p>\n<h5>=find\u547d\u4ee4\u7684-o\/-regex\u9009\u9879=<\/h5>\n<p>\u6807\u9898\u867d\u7136\u6bd4\u8f83\u62d7\u53e3\uff0c\u4f46\u529f\u80fd\u6bd4\u8f83\u5b9e\u7528\uff0c\u4e4b\u524d\u6709\u7528\u8fc7\uff0c\u4f46\u662f\u6ca1\u6709\u603b\u7ed3\u8fc7\uff0c\u56e0\u6b64\uff0c\u5728\u8fd9\u91cc\u7528\u4e00\u7bc7\u6587\u7ae0\u8bb0\u5f55\u4e00\u4e0b\u3002<\/p>\n<pre class=\"lang:default decode:true\">#\u9700\u6c42\uff1a\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u7684JPG\u548cPNG\u7c7b\u578b\u7684\u56fe\u7247\u6587\u4ef6\n\n#\u65b9\u6cd5\u4e00\nfind -maxdepth 2 -type f \\( -iname \\*.jpg -o -iname \\*.png \\)  #-maxdepth\u9009\u9879\u9700\u8981\u653e\u5728-type\u9009\u9879\u4e4b\u524d\nfind -maxdepth 2 -type f -mtime -7 \\( '*.jpg' -o -name '*.png' \\)\n\n#\u65b9\u6cd5\u4e8c\nfind -maxdepth 2 -iregex '.*\\.\\(jpg\\|png\\)$'\n\n#\u65b9\u6cd5\u4e09\nfind -maxdepth 2 -regextype posix-extended -regex '.*\\.(jpg|png)$'<\/pre>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/15308\/how-to-use-find-command-to-search-for-multiple-extensions\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/15308\/how-to-use-find-command-to-search-for-multiple-extensions<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/7190565\/unix-find-multiple-file-types\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/7190565\/unix-find-multiple-file-types<\/a><\/li>\n<\/ul>\n<h5>=find\u547d\u4ee4\u7684-path\/-prune\u9009\u9879=<\/h5>\n<pre class=\"lang:default decode:true\">#looks for files we can write to that don't belong to us\uff08\u6ce8\u610f\u5176\u4e2d-path\u9009\u9879\u4e4b\u540e\u7684\u5199\u6cd5\uff0c\u5e26\u6709\u901a\u914d\u7b26\uff09\nif [ \"$thorough\" = \"1\" ]; then\n    grfilesall=`find \/ -writable -not -user \\`whoami\\` -type f -not -path \"\/proc\/*\" -exec ls -al {} \\; 2&gt;\/dev\/null`\n    if [ \"$grfilesall\" ]; then\n        echo -e \"\\e[00;31mFiles not owned by user but writable by group:\\e[00m\\n$grfilesall\" |tee -a $report 2&gt;\/dev\/null\n        echo -e \"\\n\" |tee -a $report 2&gt;\/dev\/null\n    else\n        :\n    fi\nfi\n\n#list all world-writable files excluding \/proc\uff08\u300e\u975e\u300f\u7684\u53e6\u4e00\u79cd\u5199\u6cd5 -not\uff09\nif [ \"$thorough\" = \"1\" ]; then\nwwfiles=`find \/ ! -path \"*\/proc\/*\" -perm -2 -type f -print 2&gt;\/dev\/null`\n    if [ \"$wwfiles\" ]; then\n        echo -e \"\\e[00;31mWorld-writable files (excluding \/proc):\\e[00m\\n$wwfiles\" |tee -a $report 2&gt;\/dev\/null\n        echo -e \"\\n\" |tee -a $report 2&gt;\/dev\/null\n    else\n        :\n    fi\n  else\n    :\nfi<\/pre>\n<pre class=\"lang:default decode:true  \">-path pattern\n    File name matches shell pattern pattern. The metacharacters do not treat `\/' or `.' specially; so, for example,\n            find . -path \".\/sr*sc\"\n    will print an entry for a directory called `.\/src\/misc' (if one exists). To ignore a whole directory tree, use -prune rather than checking every file in the tree. For example, to skip the directory `src\/emacs' and all files and directories under it, and print the names of the other files found, do something like this:\n            find . -path .\/src\/emacs -prune -o -print\n    Note that the pattern match test applies to the whole file name, starting from one of the start points named on the command line.  It would only make sense  to  use  an  absolute path name here if the relevant start point is also an absolute path.  This means that this command will never match any thing:\n            find bar -path \/foo\/bar\/myfile -print\n    The predicate -path is also supported by HP-UX find and will be in a forthcoming version of the POSIX standard.\n\n# -path \u9009\u9879\u540e\u9762\u63a5\u7684\u662f\u4e00\u4e2a\"pattern\"\uff0c\u5373\u6a21\u5f0f\u5339\u914d\u4e32\uff0c\u5b83\u7684\u4f5c\u7528\u53ea\u662f\u5728\u6700\u540e\u5224\u5b9a\u662f\u5426\u6253\u5370(\u4f46\u5df2\u7ecf\u8fdb\u884c\u4e86\u641c\u7d22\u64cd\u4f5c)\uff1b\u5982\u679c\u4e00\u5f00\u59cb\u5c31\u4e0d\u60f3\u8981\u641c\u7d22\u67d0\u4e2a\u76ee\u5f55\uff0c\u8bf7\u4f7f\u7528 -prune \u9009\u9879\uff0c\u76f4\u63a5\u8df3\u8fc7\u641c\u7d22\u8be5\u76ee\u5f55\uff0c\u901f\u5ea6\u4f1a\u66f4\u5feb\uff0c\u6548\u7387\u66f4\u9ad8\n\n-prune\n    True; if the file is a directory, do not descend into it. If -depth is given, false; no effect.  Because -delete implies -depth, you cannot usefully use -prune and -delete together.<\/pre>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= =find\u547d\u4ee4\u7684-o\/-regex\u9009\u9879= \u6807\u9898\u867d\u7136\u6bd4\u8f83\u62d7\u53e3\uff0c\u4f46\u529f\u80fd\u6bd4\u8f83\u5b9e\u7528\uff0c\u4e4b\u524d\u6709\u7528\u8fc7\uff0c\u4f46\u662f\u6ca1 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,7,12],"tags":[89,19],"class_list":["post-2510","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","category-tools","tag-find","tag-tips"],"views":7262,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2510"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2510\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}