{"id":54,"date":"2023-06-30T11:23:12","date_gmt":"2023-06-30T03:23:12","guid":{"rendered":"https:\/\/www.waidts.com\/?p=54"},"modified":"2023-06-30T11:23:12","modified_gmt":"2023-06-30T03:23:12","slug":"linux-script%ef%bc%9a%e8%87%aa%e5%8b%95%e5%82%99%e4%bb%bd%e6%88%96%e5%88%aa%e9%99%a4%e8%b6%85%e9%81%8e%e7%89%b9%e5%ae%9a%e6%99%82%e9%96%93%e4%b9%8b%e9%81%8e%e6%9c%9f%e6%aa%94%e6%a1%88","status":"publish","type":"post","link":"https:\/\/www.waidts.com\/index.php\/2023\/06\/30\/linux-script%ef%bc%9a%e8%87%aa%e5%8b%95%e5%82%99%e4%bb%bd%e6%88%96%e5%88%aa%e9%99%a4%e8%b6%85%e9%81%8e%e7%89%b9%e5%ae%9a%e6%99%82%e9%96%93%e4%b9%8b%e9%81%8e%e6%9c%9f%e6%aa%94%e6%a1%88\/","title":{"rendered":"Linux Script\uff1a\u81ea\u52d5\u5099\u4efd\u6216\u522a\u9664\u8d85\u904e\u7279\u5b9a\u6642\u9593\u4e4b\u904e\u671f\u6a94\u6848"},"content":{"rendered":"\n<p>\u5728\u4f7f\u7528 linux \u6642\uff0c\u6709\u6642\u5019\u6211\u5011\u6703\u60f3\u8981\u6aa2\u67e5\u7279\u5b9a\u76ee\u9304\u4e0b\u7684\u6240\u6709\u6216\u67d0\u4e9b\u6a94\u6848\uff0c<br>\u770b\u770b\u662f\u4e0d\u662f\u9019\u4e9b\u6a94\u6848\u5df2\u7d93\u8d85\u904e\u6642\u6548\uff0c\u82e5\u8d85\u904e\u5247\u522a\u9664\u6216\u79fb\u52d5\u5230\u5176\u4ed6\u5099\u4efd\u5a92\u9ad4\uff0c<br>\u9019\u901a\u5e38\u6703\u7528\u5728\u7cfb\u7d71 log \u7684\u5099\u4efd\u7b49\uff0c\u8981\u9054\u6210\u9019\u500b\u76ee\u7684\uff0c\u6211\u5011\u8a72\u600e\u9ebc\u505a\u5462\uff1f<br>\u9996\u5148\u6211\u5011\u8981\u5229\u7528 linux \u4e2d\u975e\u5e38\u5f37\u5927\u7684\u6307\u4ee4 find\uff0c<br>\u5229\u7528 find \u627e\u5230\u7b26\u5408\u7279\u5b9a\u898f\u5247\u7684\u6a94\u6848\u5f8c\u518d\u4f7f\u7528\u6307\u4ee4\u53c3\u6578-exec\uff0c<br>\u9019\u500b\u53c3\u6578\u53ef\u4ee5\u5c07 find \u5230\u7684\u7d50\u679c\u63a5\u904e\u4f86\u57f7\u884c\uff0c\u5982\u679c\u7528\u5f97\u597d\uff0c\u61c9\u8a72\u662f\u9805\u975e\u5e38\u597d\u7528\u7684\u5de5\u5177\u3002<br>\u8aaa\u4e86\u9019\u9ebc\u591a\uff0c\u5148\u4f86\u500b\u7c21\u55ae\u7684\u4f8b\u5b50\uff0c\u4f8b\u5982\u8981\u628a tmp \u8cc7\u6599\u593e\u5e95\u4e0b\u7684 .txt \u6a94\u5099\u4efd\u5230\u53e6\u4e00\u500b\u5730\u65b9\uff1a<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"># find \/tmp\/ -type f -name &#8220;*.txt&#8221; -exec cp {} ~\/txt \\;<\/h5>\n\n\n\n<p>\u9996\u5148\u5c31 find \u76f8\u95dc\u7684\u53c3\u6578\u4f5c\u8aaa\u660e\uff1a<br><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ff0000\" class=\"has-inline-color\">find \/tmp\/ -type f -name &#8220;*.txt&#8221;\u00a0<\/mark><\/strong><br><mark style=\"background-color:rgba(0, 0, 0, 0);color:#27ae00\" class=\"has-inline-color\">\/tmp\/ \u8981\u5c0b\u627e\u7684\u76ee\u6a19\u8cc7\u6599\u593e<br>-type f \u5c0b\u627e\u985e\u578b\u70ba\u6a94\u6848<br>-name\u00a0&#8220;*.txt&#8221; \u5c0b\u627e\u6a94\u540d\u70ba .txt \u7d50\u5c3e<\/mark><br><mark style=\"background-color:rgba(0, 0, 0, 0);color:#002eff\" class=\"has-inline-color\">\u82e5\u6709\u4f7f\u7528\u842c\u7528\u5b57\u5143\u661f\u865f*\u7684\u8a71\u5efa\u8b70\u52a0\u4e0a\u5f15\u865f\uff0c\u5982 &#8220;*.txt&#8221; \u6216 &#8216;*.txt&#8217;\uff0c<br>\u5426\u5247\u5728 find \u6642\u4f3c\u4e4e\u6703\u6709\u4e0d\u660e\u932f\u8aa4\u767c\u751f\uff0c\u6709\u4e9b\u8a72\u627e\u5230\u7684\u6a94\u6848\u6703\u627e\u4e0d\u5230\uff01<\/mark><\/p>\n\n\n\n<p>\u63a5\u8457\u8aaa\u660e -exec \u5f8c\u65b9\u7684\u90e8\u5206<br><strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fb0606\" class=\"has-inline-color\">-exec cp {} ~\/txt \\;<\/mark><\/strong><br><mark style=\"background-color:rgba(0, 0, 0, 0);color:#359f00\" class=\"has-inline-color\">cp \u6307\u4ee4<br>{} \u627e\u5230\u7684\u7d50\u679c\u6a94\u6848<br>~\/txt cp \u7684\u53c3\u6578<br>\\; \u6307\u4ee4\u7684\u7d50\u675f\u7b26\u865f<\/mark><\/p>\n\n\n\n<p>\u4e0b\u9762\u9019\u884c\u6307\u4ee4\u5c31\u662f\u627e\u5230 \/tmp\/ \u8cc7\u6599\u593e\u5e95\u4e0b\u8d85\u904e\u4e00\u5929\u7684 .log \u6a94\uff0c\u7136\u5f8c\u628a\u4ed6\u5011\u90fd\u522a\u6389\uff0c<br><mark style=\"background-color:rgba(0, 0, 0, 0);color:#239900\" class=\"has-inline-color\">\u5176\u4e2d -mtime +1 \u5c31\u662f\u8981\u627e\u8d85\u904e\u4e00\u5929\u6c92\u6709\u88ab\u4fee\u6539\u7684\u6a94\u6848\u3002<\/mark><\/p>\n\n\n\n<h5 class=\"wp-block-heading\"># find \/tmp\/ -type f -name &#8220;*.log&#8221; -mtime +1 -exec rm -rf {} \\;<\/h5>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528 linux \u6642\uff0c\u6709\u6642\u5019\u6211\u5011\u6703\u60f3\u8981\u6aa2\u67e5\u7279\u5b9a\u76ee\u9304\u4e0b\u7684\u6240\u6709\u6216\u67d0\u4e9b\u6a94\u6848\uff0c\u770b\u770b\u662f\u4e0d\u662f\u9019\u4e9b\u6a94\u6848\u5df2\u7d93\u8d85\u904e\u6642\u6548\uff0c\u82e5\u8d85\u904e &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.waidts.com\/index.php\/2023\/06\/30\/linux-script%ef%bc%9a%e8%87%aa%e5%8b%95%e5%82%99%e4%bb%bd%e6%88%96%e5%88%aa%e9%99%a4%e8%b6%85%e9%81%8e%e7%89%b9%e5%ae%9a%e6%99%82%e9%96%93%e4%b9%8b%e9%81%8e%e6%9c%9f%e6%aa%94%e6%a1%88\/\"> <span class=\"screen-reader-text\">Linux Script\uff1a\u81ea\u52d5\u5099\u4efd\u6216\u522a\u9664\u8d85\u904e\u7279\u5b9a\u6642\u9593\u4e4b\u904e\u671f\u6a94\u6848<\/span> \u95b1\u8b80\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-linux-script"],"_links":{"self":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":1,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts\/54\/revisions\/55"}],"wp:attachment":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}