{"id":3543,"date":"2025-09-10T01:33:49","date_gmt":"2025-09-09T17:33:49","guid":{"rendered":"https:\/\/guerilla.ddns.net\/wp\/?p=3543"},"modified":"2025-09-10T01:41:54","modified_gmt":"2025-09-09T17:41:54","slug":"find-all-files-containing-a-specific-text-string-on-linux","status":"publish","type":"post","link":"https:\/\/guerilla.ddns.net\/wp\/?p=3543","title":{"rendered":"Find all files containing a specific text (string) on Linux"},"content":{"rendered":"<p>\u5728\u76ee\u524d\u76ee\u9304\u4e0b\uff0c\u627e\u5c0b\u54ea\u4e9b\u6a94\u6848\u4e2d\u6709 pattern \u6587\u5b57\uff08<span style=\"font-family: 'courier new', courier, monospace;\">-r<\/span> \u5305\u542b\u5b50\u76ee\u9304, \u4e5f\u53ef\u4ee5\u7528\u5927\u5beb\u7684 <span style=\"font-family: 'courier new', courier, monospace;\">-R<\/span>\uff09<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">grep -r &quot;pattern&quot; .<\/code><\/pre>\n<p>&nbsp;<br \/>\n\u6216\u8005\u52a0\u5165 -i \u4e0d\u7ba1\u5927\u5c0f\u5beb<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">grep -ri &quot;pattern&quot; .<\/code><\/pre>\n<p>&nbsp;<br \/>\n\u5176\u4ed6\u9084\u6709\u22ef\u22ef<br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">-n<\/span> (line number): \u986f\u793a\u884c\u6578\uff08pattern \u5728\u7b2c\u5e7e\u884c\u627e\u5230\u7684\uff09<br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">-l<\/span> (files with matches): \u53ea\u8981\u986f\u793a\u6a94\u6848\u540d\u7a31\uff0c\u5176\u4ed6\u7684\u8cc7\u8a0a\u90fd\u4e0d\u8981\uff08\u4e7e\u6de8\uff09<br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">-w<\/span> (whole word): \u6bd4\u5c0d\u6642\u8981\u7b26\u5408\u5b8c\u6574\u5b57\u4e32<br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">&#8211;include=&#8217;*.ext&#8217;<\/span> (include specific file types): \u9650\u5236\u53ea\u5c0b\u627e\u67d0\u4e9b\u7b26\u5408\u689d\u4ef6\u7684\u6a94\u6848<br \/>\n<span style=\"font-family: 'courier new', courier, monospace;\">&#8211;exclude-dir=&#8221;dirname&#8221;<\/span> (exclude specific directories): \u8df3\u904e\u67d0\u76ee\u9304\u4e0d\u8981\u5c0b\u627e<br \/>\n&nbsp;<br \/>\n\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">grep -rinl &quot;pattern&quot; \/path\/to\/start_search --exclude-dir=&quot;temp&quot;<\/code><\/pre>\n<p>&nbsp;<br \/>\n\u5982\u679c\u8981\u653e\u5728\u5225\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u7528 <span style=\"font-family: 'courier new', courier, monospace;\">-e<\/span> \u6307\u5b9a\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">grep -rnw &#039;\/path\/to\/somewhere\/&#039; -e &#039;pattern&#039;<\/code><\/pre>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\nSource: <a href=\"https:\/\/stackoverflow.com\/questions\/16956810\/find-all-files-containing-a-specific-text-string-on-linux\" target=\"_blank\" rel=\"noopener\">Find all files containing a specific text (string) on Linux<\/a><br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n#find #text #string #terminal<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u76ee\u524d\u76ee\u9304\u4e0b\uff0c\u627e\u5c0b\u54ea\u4e9b\u6a94\u6848\u4e2d\u6709 pattern \u6587\u5b57\uff08-r \u5305\u542b\u5b50\u76ee\u9304, \u4e5f\u53ef\u4ee5\u7528\u5927\u5beb\u7684 -R\uff09 grep &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[179],"tags":[63],"class_list":["post-3543","post","type-post","status-publish","format-standard","hentry","category-infotech","tag-linux"],"_links":{"self":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3543"}],"version-history":[{"count":6,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3543\/revisions"}],"predecessor-version":[{"id":3549,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3543\/revisions\/3549"}],"wp:attachment":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}