{"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":[],"views":6797,"_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}]}}