{"id":4220,"date":"2022-10-16T15:36:29","date_gmt":"2022-10-16T07:36:29","guid":{"rendered":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/?p=4220"},"modified":"2022-10-16T15:36:30","modified_gmt":"2022-10-16T07:36:30","slug":"find-egrep","status":"publish","type":"post","link":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/2022\/10\/find-egrep\/","title":{"rendered":"find + egrep"},"content":{"rendered":"\n<p>\u4f7f\u7528 find \u591a\u534a\u662f\u7528 wildchar \u842c\u7528\u5b57\u5143\u4f86\u641c\u5c0b\uff0c\u4f7f\u7528\u65b9\u6cd5\u7c21\u55ae\u3002\u4f46\u6709\u4e9b\u5834\u666f\u5c31\u9700\u8981\u7528 regular expression \u4f86\u627e\u7b26\u5408\u7279\u5b9a\u683c\u5f0f\u7684\u6a94\u540d\uff0c\u9019\u6642\u5019 find \u53ef\u4ee5\u52dd\u4efb\u55ce\uff1f<\/p>\n\n\n\n<p>find \u6307\u4ee4\u63d0\u4f9b\u4e86 <code>-regex<\/code> \u53c3\u6578\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u6b64\u53c3\u6578\u4f86\u6307\u5b9a\u683c\u5f0f\uff1b\u642d\u914d\u7684\u53c3\u6578\u662f <code>-regextype<\/code> \uff0cregular expression \u96d6\u8aaa\u7528\u6cd5\u5927\u81f4\u4e00\u6a23\uff0c\u4f46\u8a9e\u8a00\u96e3\u514d\u90fd\u6709\u65b9\u8a00\u5b58\u5728\uff0c\u56e0\u6b64\u53ef\u4ee5\u7528\u9019\u500b\u53c3\u6578\u4f86\u6307\u5b9a\u8981\u7528\u54ea\u7a2e regular expression \u7684\u65b9\u8a00\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u82e5\u662f\u8981\u5728 LOG_DIR \u76ee\u9304\u4e0b\u627e\u7b26\u5408 app.log.2022-10-11 \u9019\u6a23\u985e\u578b\u7684\u6a94\u540d\u7136\u5f8c\u505a\u58d3\u7e2e\uff0c\u5c31\u53ef\u4ee5\u9019\u6a23\u5beb\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \"${LOG_DIR}\" \\\n    -type f \\\n    -regextype 'posix-egrep' \\\n    -regex '.*app\\.log\\.&#91;0-9]{4}-&#91;0-9]{2}-&#91;0-9]{2}$' \\\n    -exec gzip {} \\;<\/code><\/pre>\n\n\n\n<p>\u8aaa\u660e\u5982\u4e0b<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><code>-regextype<\/code> \u524d\u9762\u8aaa\u904e\u662f\u6307\u5b9a regular expression \u7684\u65b9\u8a00\uff0c\u53ef\u4ee5\u6307\u5b9a\u9019\u4e9b awk, egrep, emacs, gnu-awk, grep, posix-awk, posix-basic, posix-egrep, posix-extended \uff0c\u9019\u908a\u6211\u5011\u7528 posix-egrep \uff0c\u78ba\u4fdd\u7b26\u5408 posix \u6a19\u6e96\u3002<\/li><li><code>-regex<\/code> \u7684\u683c\u5f0f\u6700\u524d\u9762\u4f7f\u7528\u4e86 <code>.*<\/code> \uff0c\u9019\u662f\u56e0\u70ba find \u8f38\u51fa\u6642\u7684\u6a94\u540d\u6703\u5305\u542b LOG_DIR \u8def\u5f91\uff0c\u6240\u4ee5\u5fc5\u9808\u7528 <code>.*<\/code> \u4f86\u8868\u793a\u683c\u5f0f\u4e4b\u524d\u6709\u53ef\u80fd\u6709\u4efb\u4f55\u5b57\u5143\u3002<\/li><li>egrep \u4e0d\u80fd\u7528 \\d \uff0c\u5fc5\u9808\u8981\u7528 [0-9] \u624d\u884c\uff0c\u6240\u4ee5\u9019\u908a\u7528 [0-9]{4} \u8868\u793a\u9023\u7e8c\u56db\u500b\u6578\u5b57\uff0c[0-9]{2} \u8868\u793a\u9023\u7e8c\u5169\u500b\u6578\u5b57\u3002<\/li><\/ol>\n\n\n\n<p>find \u642d\u914d regex \u5c31\u53ef\u4ee5\u66f4\u6709\u5f48\u6027\u7684\u53bb\u627e\u51fa\u7b26\u5408\u683c\u5f0f\u7684\u6a94\u540d\uff0c\u4e0d\u9700\u8981\u9077\u5c31 wildchar \u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c3\u8003\u8cc7\u6599<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/stackoverflow.com\/questions\/3185457\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pattern matching digits does not work in egrep<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 find \u591a\u534a\u662f\u7528 wildchar \u842c\u7528\u5b57\u5143\u4f86\u641c\u5c0b\uff0c\u4f7f\u7528\u65b9\u6cd5\u7c21\u55ae\u3002\u4f46\u6709\u4e9b\u5834\u666f\u5c31\u9700\u8981\u7528 regular expression \u4f86\u627e\u7b26\u5408\u7279\u5b9a\u683c\u5f0f\u7684\u6a94\u540d\uff0c\u9019\u6642\u5019 find \u53ef\u4ee5\u52dd\u4efb\u55ce\uff1f find \u6307\u4ee4\u63d0\u4f9b\u4e86 -regex \u53c3\u6578\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u6b64\u53c3\u6578\u4f86\u6307\u5b9a\u683c\u5f0f\uff1b\u642d\u914d\u7684\u53c3\u6578\u662f -regextype \uff0cregular expression \u96d6\u8aaa\u7528\u6cd5\u5927\u81f4\u4e00\u6a23\uff0c\u4f46\u8a9e\u8a00\u96e3\u514d\u90fd\u6709\u65b9\u8a00\u5b58\u5728\uff0c\u56e0\u6b64\u53ef\u4ee5\u7528\u9019\u500b\u53c3\u6578\u4f86\u6307\u5b9a\u8981\u7528\u54ea\u7a2e regular expression \u7684\u65b9\u8a00\u3002 \u6240\u4ee5\u82e5\u662f\u8981\u5728 LOG_DIR \u76ee\u9304\u4e0b\u627e\u7b26\u5408 app.log.2022-10-11 \u9019\u6a23\u985e\u578b\u7684\u6a94\u540d\u7136\u5f8c\u505a\u58d3\u7e2e\uff0c\u5c31\u53ef\u4ee5\u9019\u6a23\u5beb\uff1a \u8aaa\u660e\u5982\u4e0b -regextype \u524d\u9762\u8aaa\u904e\u662f\u6307\u5b9a regular expression \u7684\u65b9\u8a00\uff0c\u53ef\u4ee5\u6307\u5b9a\u9019\u4e9b awk, egrep, emacs, gnu-awk, grep, posix-awk, posix-basic, posix-egrep, posix-extended \uff0c\u9019\u908a\u6211\u5011\u7528 posix-egrep \uff0c\u78ba\u4fdd\u7b26\u5408 posix \u6a19\u6e96\u3002 -regex \u7684\u683c\u5f0f\u6700\u524d\u9762\u4f7f\u7528\u4e86 .* \uff0c\u9019\u662f\u56e0\u70ba find \u8f38\u51fa\u6642\u7684\u6a94\u540d\u6703\u5305\u542b LOG_DIR \u8def\u5f91\uff0c\u6240\u4ee5\u5fc5\u9808\u7528 .* &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/2022\/10\/find-egrep\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;find + egrep&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[68,29],"class_list":["post-4220","post","type-post","status-publish","format-standard","hentry","category-linux-","tag-find","tag-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2MOxp-164","_links":{"self":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts\/4220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/comments?post=4220"}],"version-history":[{"count":1,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts\/4220\/revisions"}],"predecessor-version":[{"id":4221,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/posts\/4220\/revisions\/4221"}],"wp:attachment":[{"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/media?parent=4220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/categories?post=4220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ellery.no-ip.info\/wp\/thinkingmore\/wp-json\/wp\/v2\/tags?post=4220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}