{"id":1127,"date":"2018-08-15T10:59:00","date_gmt":"2018-08-15T05:29:00","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=1127"},"modified":"2019-04-09T16:21:41","modified_gmt":"2019-04-09T10:51:41","slug":"search-for-files-and-folders","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/search-for-files-and-folders\/","title":{"rendered":"How to search files and folders via SSH"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/search-for-files-and-folders\/#Search_for_Files_and_Folders_via_SSH\" >Search for Files and Folders via SSH<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/search-for-files-and-folders\/#To_search_a_file_location\" >To search a file location:<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"Search_for_Files_and_Folders_via_SSH\"><\/span>Search for Files and Folders via SSH<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Here i will guide you how to search for files and folders via SSH.<\/p>\n<p>In some cases you would need to find the location of a given file or to search for a certain text in all files under a directory. SSH provides two different commands, which can be used to accomplish this.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"To_search_a_file_location\"><\/span>To search a file location:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In order to search for a file location you can use the\u00a0<strong>find<\/strong>\u00a0command.\u00a0<strong>Find<\/strong>\u00a0is a very powerful tool and accepts various arguments allowing you to specify the exact search term (i.e search by name, by type or even by modified time).<\/p>\n<p>For example, to search for a file called\u00a0<em>myFile.txt<\/em>\u00a0under the current folder (and all subfolders), you would need to use the following command:<\/p>\n<pre>find . -name myFile.txt<\/pre>\n<p>If you are uncertain about the file name or would like to match a part of the name, you can use a wildcard pattern:<\/p>\n<pre>find . -name\"myFile*\"<\/pre>\n<p>If you would like to list only directories and leave all files out of the result:<\/p>\n<pre>find . -type d<\/pre>\n<p>Or if you want to filter only files modified in the last 2 days, you would need to use:<\/p>\n<pre>find . -mtime -2<\/pre>\n<div id=\"attachment_1428\" style=\"width: 681px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1428\" class=\"wp-image-1428 size-full\" src=\"https:\/\/www.coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/search-files.png\" alt=\"search file\" width=\"671\" height=\"662\" srcset=\"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/search-files.png 671w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/search-files-300x296.png 300w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><p id=\"caption-attachment-1428\" class=\"wp-caption-text\">search file<\/p><\/div>\n<p>You can also search for a given text in the files content as well. The command you should be using in this case is\u00a0<strong>grep<\/strong>. Grep is a very powerful tool and accepts various command line arguments. For a full list it is recommended to check the manual pages by typing\u00a0<strong>man grep<\/strong>.<\/p>\n<p>An example of using\u00a0<strong>grep<\/strong>\u00a0to find a certain text can be found below:<\/p>\n<pre>grep \"database\" configuration.php<\/pre>\n<p>The above command instructs\u00a0<strong>grep<\/strong>\u00a0to look for the string \u201c<em>database<\/em>\u201d in the\u00a0<em>configuration.php<\/em>\u00a0file and display the containing line. If you don\u2019t know which file contains the text, you can use:<\/p>\n<pre>grep -l \"database\" *<\/pre>\n<p>This will display the filenames containing the word &#8220;<em>database&#8221;<\/em>, but will not actually list the line containing it.<\/p>\n<p>Grep can also be used to filter the results from other commands. For example, the line below will only output configuration.php result:<\/p>\n<pre>ls -la | grep configuration.php<\/pre>\n<p>In some rare cases, find and grep may prove not useful. For example, to find a certain file in the whole<a href=\"https:\/\/www.squarebrothers.com\/dedicated-server-in-india\/\" rel=\"nofollow noopener\" target=\"_blank\"> server,<\/a> it would be best to use an alternative command &#8211;\u00a0<strong>whereis<\/strong>\u00a0or\u00a0<strong>which<\/strong>:<\/p>\n<pre>whereis perl<\/pre>\n<p>or<\/p>\n<pre>which perl<\/pre>\n<p>The execution of the above commands will locate the\u00a0<em>perl binary<\/em>\u00a0and display the full path(s) to it.<\/p>\n<p>And to know the basic or How to use the GREP commands in Linux <a href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/how-to-use-the-grep-commands-in-linux\/\">click here<\/a> to go.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Search for Files and Folders via SSH Here i will guide you how to search for files and folders via SSH. In some cases you would need to find the location of a given file or to search for a certain text in all files under a directory. SSH provides [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1130,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[153],"tags":[118,93,117],"class_list":["post-1127","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-7-rhel-7","tag-configuration-php","tag-directories","tag-grep"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/08\/title.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-ib","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1127"}],"version-history":[{"count":0,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1127\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/1130"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}