{"id":161851,"date":"2019-11-17T07:52:32","date_gmt":"2019-11-16T23:52:32","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=161851"},"modified":"2019-10-29T22:12:52","modified_gmt":"2019-10-29T14:12:52","slug":"find-xargs","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/find-xargs.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528find\u548cxargs\u67e5\u627e\u548c\u5904\u7406\u6587\u4ef6"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nfind \u662f\u65e5\u5e38\u5de5\u5177\u7bb1\u4e2d\u529f\u80fd\u5f3a\u5927\u3001\u7075\u6d3b\u7684\u547d\u4ee4\u884c\u7a0b\u5e8f\u4e4b\u4e00\u3002\u5b83\u5982\u5b83\u540d\u5b57\u6240\u6697\u793a\u7684\uff1a\u67e5\u627e\u7b26\u5408\u4f60\u6307\u5b9a\u6761\u4ef6\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u3002\u501f\u52a9 -exec \u6216 -delete \u4e4b\u7c7b\u7684\u53c2\u6570\uff0c\u4f60\u53ef\u4ee5\u8ba9\u5b83\u5bf9\u627e\u5230\u7684\u6587\u4ef6\u8fdb\u884c\u64cd\u4f5c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728\u547d\u4ee4\u884c\u63d0\u793a\u7cfb\u5217\u7684\u8fd9\u4e00\u671f\u4e2d\uff0c\u4f60\u5c06\u4f1a\u770b\u5230 find \u547d\u4ee4\u7684\u4ecb\u7ecd\uff0c\u5e76\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u5185\u7f6e\u547d\u4ee4\u6216\u4f7f\u7528 xargs \u547d\u4ee4\u5904\u7406\u6587\u4ef6\u3002<\/p>\n

\u67e5\u627e\u6587\u4ef6<\/strong><\/div>\n

find \u81f3\u5c11\u8981\u52a0\u4e0a\u67e5\u627e\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff0c\u6b64\u547d\u4ee4\u5c06\u67e5\u627e\uff08\u5e76\u6253\u5370\uff09\u7cfb\u7edf\u4e0a\u7684\u6bcf\u4e2a\u6587\u4ef6\uff1a<\/p>\n

find \/<\/pre>\n

\u7531\u4e8e\u4e00\u5207\u7686\u6587\u4ef6\uff0c\u56e0\u6b64\u4f60\u4f1a\u770b\u5230\u5927\u91cf\u7684\u8f93\u51fa\u3002\u8fd9\u53ef\u80fd\u65e0\u6cd5\u5e2e\u52a9\u4f60\u627e\u5230\u6240\u9700\u7684\u5185\u5bb9\u3002\u4f60\u53ef\u4ee5\u66f4\u6539\u8def\u5f84\u53c2\u6570\u7f29\u5c0f\u8303\u56f4\uff0c\u4f46\u8fd9\u5b9e\u9645\u4e0a\u5e76\u6ca1\u6709\u6bd4\u4f7f\u7528 ls \u547d\u4ee4\u66f4\u597d\u3002\u56e0\u6b64\uff0c\u4f60\u9700\u8981\u8003\u8651\u8981\u67e5\u627e\u7684\u5185\u5bb9\u3002
\n\u4e5f\u8bb8\u4f60\u60f3\u5728\u5bb6\u76ee\u5f55\u4e2d\u67e5\u627e\u6240\u6709 JPEG \u6587\u4ef6\u3002 -name \u53c2\u6570\u5141\u8bb8\u4f60\u5c06\u7ed3\u679c\u9650\u5236\u4e3a\u4e0e\u7ed9\u5b9a\u6a21\u5f0f\u5339\u914d\u7684\u6587\u4ef6\u3002<\/p>\n

find ~ -name '*jpg'<\/pre>\n

\u4f46\u662f\u7b49\u7b49\uff01\u5982\u679c\u5176\u4e2d\u4e00\u4e9b\u6269\u5c55\u540d\u662f\u5927\u5199\u600e\u4e48\u529e\uff1f -iname \u7c7b\u4f3c\u4e8e -name\uff0c\u4f46\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff1a<\/p>\n

find ~ -iname '*jpg'<\/pre>\n

\u5f88\u597d\uff01\u4f46\u662f 8.3 \u547d\u540d\u65b9\u6848\u51fa\u81ea 1985 \u5e74\u3002\u67d0\u4e9b\u56fe\u7247\u7684\u6269\u5c55\u540d\u53ef\u80fd\u662f .jpeg\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6a21\u5f0f\u4f7f\u7528\u201c\u6216\u201d\uff08-o\uff09\u8fdb\u884c\u7ec4\u5408\u3002\u62ec\u53f7\u9700\u8981\u8f6c\u4e49\uff0c\u4ee5\u4fbf\u4f7f find \u547d\u4ee4\u800c\u4e0d\u662f shell \u7a0b\u5e8f\u5c1d\u8bd5\u89e3\u91ca\u5b83\u4eec\u3002<\/p>\n

find ~ \\( -iname 'jpeg' -o -iname 'jpg' \\)<\/pre>\n

\u66f4\u8fdb\u4e00\u6b65\u3002\u5982\u679c\u4f60\u6709\u4e00\u4e9b\u4ee5 jpg \u7ed3\u5c3e\u7684\u76ee\u5f55\u600e\u4e48\u529e\uff1f\uff08\u6211\u4e0d\u61c2\u4f60\u4e3a\u4ec0\u4e48\u5c06\u76ee\u5f55\u547d\u540d\u4e3a bucketofjpg \u800c\u4e0d\u662f pictures\uff1f\uff09\u6211\u4eec\u53ef\u4ee5\u52a0\u4e0a -type \u53c2\u6570\u6765\u4ec5\u67e5\u627e\u6587\u4ef6\uff1a<\/p>\n

find ~ \\( -iname '*jpeg' -o -iname '*jpg' \\) -type f<\/pre>\n

\u6216\u8005\uff0c\u4e5f\u8bb8\u4f60\u60f3\u627e\u5230\u90a3\u4e9b\u540d\u5b57\u5947\u602a\u7684\u76ee\u5f55\uff0c\u4ee5\u4fbf\u4e4b\u540e\u53ef\u4ee5\u91cd\u547d\u540d\u5b83\u4eec\uff1a<\/p>\n

find ~ \\( -iname '*jpeg' -o -iname '*jpg' \\) -type d<\/pre>\n

\u6700\u8fd1\u4f60\u62cd\u6444\u4e86\u5f88\u591a\u7167\u7247\uff0c\u56e0\u6b64\u4f7f\u7528 -mtime\uff08\u4fee\u6539\u65f6\u95f4\uff09\u5c06\u8303\u56f4\u7f29\u5c0f\u5230\u6700\u8fd1\u4e00\u5468\u4fee\u6539\u8fc7\u7684\u6587\u4ef6\u3002 -7 \u8868\u793a 7 \u5929\u6216\u66f4\u77ed\u65f6\u95f4\u5185\u4fee\u6539\u7684\u6240\u6709\u6587\u4ef6\u3002<\/p>\n

find ~ \\( -iname '*jpeg' -o -iname '*jpg' \\) -type f -mtime -7<\/pre>\n
\u4f7f\u7528 xargs \u8fdb\u884c\u64cd\u4f5c<\/strong><\/div>\n

xargs \u547d\u4ee4\u4ece\u6807\u51c6\u8f93\u5165\u6d41\u4e2d\u83b7\u53d6\u53c2\u6570\uff0c\u5e76\u57fa\u4e8e\u5b83\u4eec\u6267\u884c\u547d\u4ee4\u3002\u7ee7\u7eed\u4f7f\u7528\u4e0a\u4e00\u8282\u4e2d\u7684\u793a\u4f8b\uff0c\u5047\u8bbe\u4f60\u8981\u5c06\u4e0a\u5468\u4fee\u6539\u8fc7\u7684\u5bb6\u76ee\u5f55\u4e2d\u7684\u6240\u6709 JPEG \u6587\u4ef6\u590d\u5236\u5230 U \u76d8\uff0c\u4ee5\u4fbf\u63d2\u5230\u7535\u5b50\u76f8\u518c\u4e0a\u3002\u5047\u8bbe\u4f60\u5df2\u7ecf\u5c06 U \u76d8\u6302\u8f7d\u5230 \/media\/photo_display\u3002<\/p>\n

find ~ \\( -iname '*jpeg' -o -iname '*jpg' \\) -type f -mtime -7 -print0 | xargs -0 cp -t \/media\/photo_display<\/pre>\n

\u8fd9\u91cc\u7684 find \u547d\u4ee4\u4e0e\u4ee5\u524d\u7684\u7248\u672c\u7565\u6709\u4e0d\u540c\u3002-print0 \u547d\u4ee4\u8ba9\u8f93\u51fa\u6709\u4e00\u4e9b\u66f4\u6539\uff1a\u5b83\u4e0d\u4f7f\u7528\u6362\u884c\u7b26\uff0c\u800c\u662f\u6dfb\u52a0\u4e86\u4e00\u4e2a null \u5b57\u7b26\u3002xargs \u7684 -0\uff08\u96f6\uff09\u9009\u9879\u53ef\u8c03\u6574\u89e3\u6790\u4ee5\u8fbe\u5230\u9884\u671f\u6548\u679c\u3002\u8fd9\u5f88\u91cd\u8981\uff0c\u4e0d\u7136\u5bf9\u5305\u542b\u7a7a\u683c\u3001\u5f15\u53f7\u6216\u5176\u4ed6\u7279\u6b8a\u5b57\u7b26\u7684\u6587\u4ef6\u540d\u6267\u884c\u64cd\u4f5c\u53ef\u80fd\u65e0\u6cd5\u6309\u9884\u671f\u8fdb\u884c\u3002\u5bf9\u6587\u4ef6\u91c7\u53d6\u4efb\u4f55\u64cd\u4f5c\u65f6\uff0c\u90fd\u5e94\u4f7f\u7528\u8fd9\u4e9b\u9009\u9879\u3002
\ncp \u547d\u4ee4\u7684 -t \u53c2\u6570\u5f88\u91cd\u8981\uff0c\u56e0\u4e3a cp \u901a\u5e38\u8981\u6c42\u76ee\u7684\u5730\u5740\u5728\u6700\u540e\u3002\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528 xargs \u800c\u4f7f\u7528 find \u7684 -exec \u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u4f46\u662f xargs \u7684\u65b9\u5f0f\u4f1a\u66f4\u5feb\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u5927\u91cf\u6587\u4ef6\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5355\u6b21\u8c03\u7528 cp\u3002<\/p>\n

\u4e86\u89e3\u66f4\u591a<\/strong><\/div>\n

\u8fd9\u7bc7\u6587\u7ae0\u4ec5\u4ec5\u662f find \u53ef\u4ee5\u505a\u7684\u4e8b\u60c5\u7684\u8868\u9762\u3002 find \u652f\u6301\u57fa\u4e8e\u6743\u9650\u3001\u6240\u6709\u8005\u3001\u8bbf\u95ee\u65f6\u95f4\u7b49\u7684\u6d4b\u8bd5\u3002\u5b83\u751a\u81f3\u53ef\u4ee5\u5c06\u641c\u7d22\u8def\u5f84\u4e2d\u7684\u6587\u4ef6\u4e0e\u5176\u4ed6\u6587\u4ef6\u8fdb\u884c\u6bd4\u8f83\u3002\u5c06\u6d4b\u8bd5\u4e0e\u5e03\u5c14\u903b\u8f91\u76f8\u7ed3\u5408\uff0c\u53ef\u4ee5\u4e3a\u4f60\u63d0\u4f9b\u60ca\u4eba\u7684\u7075\u6d3b\u6027\uff0c\u4ee5\u7cbe\u786e\u5730\u627e\u5230\u4f60\u8981\u67e5\u627e\u7684\u6587\u4ef6\u3002\u4f7f\u7528\u5185\u7f6e\u547d\u4ee4\u6216\u7ba1\u9053\u4f20\u9012\u7ed9 xargs\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u5904\u7406\u5927\u91cf\u6587\u4ef6\u3002<\/p>\n

via: https:\/\/fedoramagazine.org\/command-line-quick-tips-locate-and-process-files-with-find-and-xargs\/<\/p>\n

\u4f5c\u8005\uff1aBen Cotton \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1ageekpi \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u547d\u4ee4\u884c\u63d0\u793a\u7cfb\u5217\u7684\u8fd9\u4e00\u671f\u4e2d\uff0c\u4f60\u5c06\u4f1a\u770b\u5230 find \u547d\u4ee4\u7684\u4ecb\u7ecd\uff0c\u5e76\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u5185\u7f6e\u547d\u4ee4\u6216\u4f7f\u7528 xargs \u547d\u4ee4\u5904 […]<\/p>\n","protected":false},"author":1920,"featured_media":161853,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-161851","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1920"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=161851"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161851\/revisions"}],"predecessor-version":[{"id":162063,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161851\/revisions\/162063"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/161853"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=161851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=161851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=161851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}