{"id":1640,"date":"2024-08-07T14:23:03","date_gmt":"2024-08-07T13:23:03","guid":{"rendered":"https:\/\/editjournal.redakt.eu\/faxmodem\/?p=1640"},"modified":"2024-08-07T14:24:12","modified_gmt":"2024-08-07T13:24:12","slug":"find-code-in-directory","status":"publish","type":"post","link":"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/find-code-in-directory\/","title":{"rendered":"Searching for code snippets in a given directory"},"content":{"rendered":"<p>One thing that saved me lots of time and potential bugs is using <code>grep<\/code> for a given string in a given directory. Imagine you decided to rename a function and you now need to update every piece of code that calls it. No chance you will remember all places where you used it, and manually looking up through each file is not an option either. Instead, simply do:<\/p>\n<pre><code>grep -inFRe \"literal code\" \/var\/www\/myproject<\/code><\/pre>\n<p>This searches for all occurrences of <code>literal code<\/code> in <code>\/var\/www\/myproject<\/code><\/p>\n<ul>\n<li><a href=\"https:\/\/www.gnu.org\/software\/grep\/manual\/grep.html#index-_002di\"><code>-i<\/code><\/a>: case insensitive search, so the input <code>literal code<\/code> will match actual code <code>Literal Code<\/code> and <code>LiTeRAl CoDe<\/code>;<\/li>\n<li><a href=\"https:\/\/www.gnu.org\/software\/grep\/manual\/grep.html#index-_002dn\"><code>-n<\/code><\/a>: for every match, show not only file name but also line number where the match is;<\/li>\n<li><a href=\"https:\/\/www.gnu.org\/software\/grep\/manual\/grep.html#index-_002dF\"><code>-F<\/code><\/a>: ensure input pattern is treated as a literal string;<\/li>\n<li><a href=\"https:\/\/www.gnu.org\/software\/grep\/manual\/grep.html#index-_002dr\"><code>-r<\/code><\/a>: search recursively in subdirectories; changing to <code>-R<\/code> will follow symlinks too;<\/li>\n<li><a href=\"https:\/\/www.gnu.org\/software\/grep\/manual\/grep.html#index-_002de\"><code>-e<\/code><\/a>: explicitly specify the input pattern, for clarity.<\/li>\n<\/ul>\n<p>See also: <a href=\"https:\/\/www.gnu.org\/software\/grep\/manual\/grep.html\"><code>man grep<\/code><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One thing that saved me lots of time and potential bugs is using grep for a given string in a given directory. Imagine you decided to rename a function and you now need to update every piece of code that calls it. No chance you will remember all places where you used it, and manually&hellip; <a class=\"more-link\" href=\"https:\/\/editjournal.redakt.eu\/faxmodem\/blog\/development\/find-code-in-directory\/\">Continue reading <span class=\"screen-reader-text\">Searching for code snippets in a given directory<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[706],"tags":[775,847],"class_list":["post-1640","post","type-post","status-publish","format-standard","hentry","category-development","tag-debian","tag-grep","entry"],"_links":{"self":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/comments?post=1640"}],"version-history":[{"count":1,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1640\/revisions"}],"predecessor-version":[{"id":1641,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/posts\/1640\/revisions\/1641"}],"wp:attachment":[{"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/media?parent=1640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/categories?post=1640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/editjournal.redakt.eu\/faxmodem\/wp-json\/wp\/v2\/tags?post=1640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}