{"id":53,"date":"2012-06-30T12:44:47","date_gmt":"2012-06-30T12:44:47","guid":{"rendered":"http:\/\/www.buildingcubes.com\/?p=53"},"modified":"2012-06-30T12:44:47","modified_gmt":"2012-06-30T12:44:47","slug":"searching-you-hard-drive-for-a-string-in-a-file","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2012\/06\/30\/searching-you-hard-drive-for-a-string-in-a-file\/","title":{"rendered":"Searching you hard drive for files or for a string in a file"},"content":{"rendered":"<p>On a linux box, there is a simple way to search for some text inside a file using regular expressions in the command line<\/p>\n<p>So, the short answer, in Linux, you can simply execute this line<\/p>\n<pre>grep -R -B3 -A4 \"MYTEXT\" \/var\/ > \/root\/findingres.txt<\/pre>\n<p>this will show you 3 lines before the text and 4 lines after the string and the file name, it will search in the \/var\/ folder, and will store the searching results to \/root\/findingres.txt<\/p>\n<p>The above is a simple example, you can use regular expressions to find more complicated stuff<\/p>\n<p>Also, if you want to search the entier hard drive for a string, and you want to search only in one type of file that you want to specify using a file extension you can use the following<\/p>\n<pre>grep -R --include=*.txt \"MYTEXT\" \/etc\/<\/pre>\n<p>Now, if you want to search for a file by file name, <\/p>\n<pre>find \/ -type f -name \"myfile.txt\"<\/pre>\n<p>would look for an exact file name, if you are looking to find a file using wildcards, for example, any file that ends in a certain extension you would<\/p>\n<pre>find \/ -type f -iname \"*.psd\"<\/pre>\n<p>If you want to include directories in your search, remove the -type flag<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On a linux box, there is a simple way to search for some text inside a file using regular expressions in the command line So, the short answer, in Linux, you can simply execute this line grep -R -B3 -A4 &#8220;MYTEXT&#8221; \/var\/ > \/root\/findingres.txt this will show you 3 lines before the text and 4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":0,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}