{"id":223,"date":"2006-09-24T16:47:11","date_gmt":"2006-09-24T13:47:11","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=223"},"modified":"2006-10-02T17:55:16","modified_gmt":"2006-10-02T14:55:16","slug":"patching-grep-to-exclude-directories-from-recursive-search","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/","title":{"rendered":"patching grep to exclude directories from recursive search"},"content":{"rendered":"<p>I always wanted to be able to control which directory grep should go into and which it should not when I use the recursive (-r) option. I wanted a way to exclude some cache or other meaningless directories from it. I am using  grep version 2.5.1 on gentoo linux (grep-2.5.1-r8).<\/p>\n<p>I&#8217;ve just found a patch on the net that does exactly that! If you check this page: <a href=\"http:\/\/savannah.gnu.org\/patch\/?func=detailitem&#038;item_id=5051\">grep &#8211; Patches: patch #5051, Exclude Directories in Recursive&#8230;<\/a> you can download a patch for the current grep version.<\/p>\n<p>I&#8217;ll show you how to apply it on a gentoo distro. It&#8217;s really simple. I am assuming that you already use a portage overlay&#8230;say it lies inside your \/usr\/local\/portage dir.<\/p>\n<p>Lines that begin with &#8220;#&#8221; should be executed as root.<br \/>\nLines that begin with &#8220;&#8212; COMMENT:&#8221;  should be read and applied.<\/p>\n<p><code><br \/>\n# mkdir -p \/usr\/local\/portage\/sys-apps\/grep\/files<br \/>\n# cp \/usr\/portage\/sys-apps\/grep\/grep-2.5.1-r8.ebuild \/usr\/portage\/sys-apps\/grep\/grep-2.5.1-r100.ebuild<br \/>\n# cp \/usr\/portage\/sys-apps\/grep\/files\/* \/usr\/local\/portage\/sys-apps\/grep\/files\/<br \/>\n# vi \/usr\/portage\/sys-apps\/grep\/grep-2.5.1-r100.ebuild<br \/>\n--- COMMENT:  find the line that says KEYWORDS=\"alpha amd64 arm hppa ia64 m68k mips ppc ~ppc-macos ppc64 s390 sh sparc x86\" and change it to: KEYWORDS=\"~x86\"  or your ~arch if it's another.<br \/>\n--- COMMENT:  add this under src_unpack():<br \/>\nepatch \u201c${FILESDIR}\u201d\/${PN}-2.5.1-exclude-dir.patch<br \/>\n# echo \"=sys-apps\/grep-2.5.1-r100 ~x86\" >> \/etc\/portage\/package\/keywords<br \/>\n--- COMMENT:  change ~x86 to your ~arch<br \/>\n--- COMMENT:  download http:\/\/savannah.gnu.org\/patch\/download.php?file_id=9836 and save it as \"grep-2.5.1-exclude-dir.patch\"<br \/>\n# mv \/path\/to\/grep-2.5.1-exclude-dir.patch \/usr\/local\/portage\/sys-apps\/grep\/files\/<br \/>\n# cd \/usr\/local\/portage\/sys-apps\/grep\/<br \/>\n# ebuild grep-2.5.1-r100.ebuild digest<br \/>\n# emerge =sys-apps\/grep-2.5.1-r100<br \/>\n<\/code><\/p>\n<p>and that&#8217;s it. The patch is applied cleanly (at least on ~x86) that I tried it and the result is this:<br \/>\n<code><br \/>\n# mkdir -p ~\/foo\/bar<br \/>\n# mkdir -p ~\/foo\/zoo<br \/>\n# echo \"test123\" >> ~\/foo\/bar\/test1.txt<br \/>\n# echo \"test123\" >> ~\/foo\/zoo\/test2.txt<br \/>\n# cd ~\/foo<br \/>\n# grep -r -n test123 *<br \/>\nbar\/test1.txt:test123<br \/>\nzoo\/test2.txt:test123<br \/>\n# grep -r test123 * --exclude-dir=zoo<br \/>\nbar\/test1.txt:test123<br \/>\n<\/code><\/p>\n<p>enjoy \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I always wanted to be able to control which directory grep should go into and which it should not when I use the recursive (-r) option. I wanted a way to exclude some cache or other meaningless directories from it. I am using grep version 2.5.1 on gentoo linux (grep-2.5.1-r8). I&#8217;ve just found a patch [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-linux"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"I always wanted to be able to control which directory grep should go into and which it should not when I use the recursive (-r) option. I wanted a way to exclude some cache or other meaningless directories from it. I am using grep version 2.5.1 on gentoo linux (grep-2.5.1-r8). I&#039;ve just found a patch\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"kargig\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#article\",\"name\":\"patching grep to exclude directories from recursive search | Into.the.Void.\",\"headline\":\"patching grep to exclude directories from recursive search\",\"author\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#organization\"},\"datePublished\":\"2006-09-24T16:47:11+03:00\",\"dateModified\":\"2006-10-02T17:55:16+03:00\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#webpage\"},\"articleSection\":\"Linux\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/#listItem\",\"name\":\"Linux\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/#listItem\",\"position\":2,\"name\":\"Linux\",\"item\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#listItem\",\"name\":\"patching grep to exclude directories from recursive search\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#listItem\",\"position\":3,\"name\":\"patching grep to exclude directories from recursive search\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/#listItem\",\"name\":\"Linux\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#organization\",\"name\":\"Into.the.Void.\",\"description\":\"Into The Void\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/\",\"sameAs\":[\"https:\\\/\\\/x.com\\\/kargig\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/\",\"name\":\"kargig\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#webpage\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/\",\"name\":\"patching grep to exclude directories from recursive search | Into.the.Void.\",\"description\":\"I always wanted to be able to control which directory grep should go into and which it should not when I use the recursive (-r) option. I wanted a way to exclude some cache or other meaningless directories from it. I am using grep version 2.5.1 on gentoo linux (grep-2.5.1-r8). I've just found a patch\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2006\\\/09\\\/24\\\/patching-grep-to-exclude-directories-from-recursive-search\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\"},\"datePublished\":\"2006-09-24T16:47:11+03:00\",\"dateModified\":\"2006-10-02T17:55:16+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/\",\"name\":\"Into.the.Void.\",\"description\":\"Into The Void\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"patching grep to exclude directories from recursive search | Into.the.Void.","description":"I always wanted to be able to control which directory grep should go into and which it should not when I use the recursive (-r) option. I wanted a way to exclude some cache or other meaningless directories from it. I am using grep version 2.5.1 on gentoo linux (grep-2.5.1-r8). I've just found a patch","canonical_url":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#article","name":"patching grep to exclude directories from recursive search | Into.the.Void.","headline":"patching grep to exclude directories from recursive search","author":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author"},"publisher":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/#organization"},"datePublished":"2006-09-24T16:47:11+03:00","dateModified":"2006-10-02T17:55:16+03:00","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#webpage"},"isPartOf":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#webpage"},"articleSection":"Linux"},{"@type":"BreadcrumbList","@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/www.void.gr\/kargig\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/#listItem","name":"Linux"}},{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/#listItem","position":2,"name":"Linux","item":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#listItem","name":"patching grep to exclude directories from recursive search"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#listItem","position":3,"name":"patching grep to exclude directories from recursive search","previousItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/#listItem","name":"Linux"}}]},{"@type":"Organization","@id":"https:\/\/www.void.gr\/kargig\/blog\/#organization","name":"Into.the.Void.","description":"Into The Void","url":"https:\/\/www.void.gr\/kargig\/blog\/","sameAs":["https:\/\/x.com\/kargig"]},{"@type":"Person","@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author","url":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/","name":"kargig"},{"@type":"WebPage","@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#webpage","url":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/","name":"patching grep to exclude directories from recursive search | Into.the.Void.","description":"I always wanted to be able to control which directory grep should go into and which it should not when I use the recursive (-r) option. I wanted a way to exclude some cache or other meaningless directories from it. I am using grep version 2.5.1 on gentoo linux (grep-2.5.1-r8). I've just found a patch","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/#breadcrumblist"},"author":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author"},"creator":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author"},"datePublished":"2006-09-24T16:47:11+03:00","dateModified":"2006-10-02T17:55:16+03:00"},{"@type":"WebSite","@id":"https:\/\/www.void.gr\/kargig\/blog\/#website","url":"https:\/\/www.void.gr\/kargig\/blog\/","name":"Into.the.Void.","description":"Into The Void","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"223","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2022-01-04 12:00:38","updated":"2026-10-21 09:25:19","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.void.gr\/kargig\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/\" title=\"Linux\">Linux<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tpatching grep to exclude directories from recursive search\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.void.gr\/kargig\/blog\/"},{"label":"Linux","link":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/"},{"label":"patching grep to exclude directories from recursive search","link":"https:\/\/www.void.gr\/kargig\/blog\/2006\/09\/24\/patching-grep-to-exclude-directories-from-recursive-search\/"}],"views":7076,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":0,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}