{"id":1624,"date":"2021-09-23T09:46:16","date_gmt":"2021-09-23T04:16:16","guid":{"rendered":"https:\/\/www.webhostingchennai.co.in\/blog\/?p=1624"},"modified":"2021-10-06T13:06:02","modified_gmt":"2021-10-06T07:36:02","slug":"find-command-in-linux","status":"publish","type":"post","link":"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/","title":{"rendered":"Find Command in Linux"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 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-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Find_Command_in_Linux\" >Find Command in Linux<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Searching_files_within_a_specified_directory\" >Searching files within a specified directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Searching_files_using_the_filename_within_a_specified_directory\" >Searching files using the filename within a specified directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Recursively_find_all_files_with_a_specified_file_extension\" >Recursively find all files with a specified file extension<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Limiting_depth_of_search\" >Limiting depth of search<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Invert_search_results\" >Invert search results<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Using_find_with_OR_operator\" >Using find with OR operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Searching_for_files_owned_by_a_particular_user\" >Searching for files owned by a particular user<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Searching_for_files_with_certain_file_permissions\" >Searching for files with certain file permissions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/chennaiwebhosting.in\/blog\/find-command-in-linux\/#Searching_for_files_with_certain_files_sizes_or_a_range_of_files\" >Searching for files with certain files sizes or a range of files<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Find_Command_in_Linux\"><\/span>Find Command in Linux<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Linux find command is being used when looking for files directly from the command line. The find command is given with search criteria such as permissions, ownership, modification, size, time, and date among others to locate the file or directory.<\/p>\n<p>The find command is available in all Linux distros by default, no need of installing special packages to use it. Due to its significance, the find command is an essential command to learn if you want to know more about the command line navigations on any <a href=\"https:\/\/www.redhat.com\/en\" rel=\"nofollow noopener\" target=\"_blank\">Linux distribution<\/a>.<\/p>\n<p>Let&#8217;s see some of the find command examples and explain the various options that we use.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<pre>$ find location comparison-criteria search term<\/pre>\n<p>Listing files in the current directory<\/p>\n<p>To list all files in a directory including files inside folders, run the command below.<\/p>\n<pre>$ find .<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Searching_files_within_a_specified_directory\"><\/span>Searching files within a specified directory<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you want to search all files in a given directory, use the find command as follows<\/p>\n<pre>$ find directory_name<\/pre>\n<p>For example, to search for all files in <strong>\/etc<\/strong> execute the command<\/p>\n<pre>$ find \/etc<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Searching_files_using_the_filename_within_a_specified_directory\"><\/span>Searching files using the filename within a specified directory<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you want to specify the search criteria using the name of the file in a directory, the syntax will be as follows<\/p>\n<pre>$ find directory_name -name &quot;file_name&quot;<\/pre>\n<p>For example, to search for Apache2 files in \/etc directory run<\/p>\n<pre>$ find \/etc -name &quot;apache2&quot;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Recursively_find_all_files_with_a_specified_file_extension\"><\/span>Recursively find all files with a specified file extension<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you want to search for particular files with a specific extension, in a given directory, the syntax will be as follows<\/p>\n<pre>$ find directory_name -name &quot;*.extension&quot;<\/pre>\n<p>For example, to search for all configuration files (.conf) in \/etc directory, execute<\/p>\n<pre>$ find \/etc -name &quot;*.conf&quot;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Limiting_depth_of_search\"><\/span>Limiting depth of search<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can also decide to limit the depth of your file search in directories. If you want to limit your file search to the first level of the directory, the syntax will be<\/p>\n<pre>$ find directory_name -maxdepth 1 -name &quot;*.conf&quot;<\/pre>\n<p>So, if you want to limit the file search to the first level directory in <strong>\/etc<\/strong> for files with <strong>.conf<\/strong> extension execute:<\/p>\n<pre>$ find \/etc -maxdepth 1 -name &quot;*.conf&quot;<\/pre>\n<p><strong>Sample output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1625 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find1.jpg\" alt=\"Find Command in Linux\" width=\"618\" height=\"330\" \/><\/p>\n<p>As seen in the output above, the file search is limited to the <strong>\/etc<\/strong> directory level. If you want to perform a more intensive search and go deeper within other directories within the <strong>\/etc<\/strong> directory, increase the maxdepth value.<\/p>\n<p>To search for files with <strong>.conf<\/strong> extension up to the 3rd directory run<\/p>\n<pre>$ find \/etc -maxdepth 3 -name &quot;*.conf&quot;<\/pre>\n<p><strong>Sample output<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1626 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find3.jpg\" alt=\"Find Command in Linux\" width=\"618\" height=\"330\" \/><\/p>\n<p>From the above output, the search goes up to the 2nd and 3rd directories.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Invert_search_results\"><\/span>Invert search results<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can also search for files that do not meet given criteria with the find command. This mode is helpful when you want to eliminate known files from the search pattern.<\/p>\n<p>To do this, use the -not -name attribute as shown<\/p>\n<pre>$ find \/etc -maxdepth 1 -not -name &quot;*.conf&quot;<\/pre>\n<p><strong>Sample output<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1627 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find4.jpg\" alt=\"Find Command in Linux\" width=\"618\" height=\"330\" \/><\/p>\n<p>The above output prints all the files that do not have the <strong><em>.conf<\/em> <\/strong>file extension.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_find_with_OR_operator\"><\/span>Using find with OR operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can choose to combine search results with find by using the OR operator which is symbolized by -o flag shown in the example below<\/p>\n<pre>$ find \/etc -maxdepth 3 -name &quot;cron&quot; -o -name &quot;ssh&quot;<\/pre>\n<p><strong>Sample output<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1628 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find5.jpg\" alt=\"Find Command in Linux\" width=\"528\" height=\"114\" \/><\/p>\n<p>The above command searches for files bearing the name <em>ssh<\/em> OR <em>cron<\/em> in the &lt;\/etc directory&gt;<\/p>\n<p>If you want to search for directories only, use the <strong>-type d<\/strong> attribute as shown in the example below.<\/p>\n<pre>$ find \/etc -type d -name &quot;ssh&quot;<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Searching_for_files_owned_by_a_particular_user\"><\/span>Searching for files owned by a particular user<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To search for files owned by a particular user in a specific directory, use the syntax:<\/p>\n<pre>$ find \/path -user username<\/pre>\n<p>For instance, to find files owned by user <strong>webhostc<\/strong> in <strong>\/home<\/strong> directory run the command below<\/p>\n<pre>$ find \/home -user webhostc<\/pre>\n<p><strong>Sample output<\/strong><\/p>\n<pre>\/home\/webhostc\r\n\/home\/webhostc\/tmp\r\n\/home\/webhostc\/imap\r\n\/home\/webhostc\/Maildir\r\n\/home\/webhostc\/.bash_logout\r\n\/home\/webhostc\/public_html\r\n\/home\/webhostc\/domains<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Searching_for_files_with_certain_file_permissions\"><\/span>Searching for files with certain file permissions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To search for files with specific file permissions, use the syntax below<\/p>\n<pre>$ find \/directory_name -type f -perm value<\/pre>\n<p>For example, to search for files with permissions 755 in <strong>\/etc<\/strong> directory, run:<\/p>\n<pre>$ find \/etc -type f -perm 755<\/pre>\n<p><strong>Sample output<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1629 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find6.jpg\" alt=\"Find Command in Linux\" width=\"618\" height=\"330\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Searching_for_files_with_certain_files_sizes_or_a_range_of_files\"><\/span>Searching for files with certain files sizes or a range of files<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Linux find command also allows users a chance to search files according to their file sizes.<\/p>\n<p><strong>Search files of N size<\/strong><\/p>\n<p>For example, to search for files which are 10kb run:<\/p>\n<pre>$ find \/etc -type f -size 10k<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1630 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find7.jpg\" alt=\"Find Command in Linux\" width=\"618\" height=\"330\" \/><\/p>\n<p><strong>To search files greater than 10kb run<\/strong><\/p>\n<pre>$ find \/etc -type f -size +10k<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1631 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find8.jpg\" alt=\"Find Command in Linux\" width=\"618\" height=\"330\" \/><\/p>\n<p><strong>To search files less than 10kb run<\/strong><\/p>\n<pre>find \/etc -type f -size -10k<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1632 size-full\" src=\"http:\/\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2021\/09\/find9.jpg\" alt=\"Find Command in Linux\" width=\"618\" height=\"330\" \/><\/p>\n<p>That&#8217;s it now for find command. If you know any other commands related to find command please comment us so that we can add it with your name.<\/p>\n<p>To know about Top 50 Linux Commands, <a href=\"https:\/\/chennaiwebhosting.in\/blog\/top-50-linux-commands\/\">Click here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find Command in Linux The Linux find command is being used when looking for files directly from the command line. The find command is given with search criteria such as permissions, ownership, modification, size, time, and date among others to locate the file or directory. The find command is available in all Linux distros by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1669,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[57,14,13,11,15],"tags":[],"class_list":["post-1624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-redhat","category-centos-6-rhel-6","category-centos-7-rhel-7","category-linux","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=1624"}],"version-history":[{"count":2,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1624\/revisions"}],"predecessor-version":[{"id":1671,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1624\/revisions\/1671"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/media\/1669"}],"wp:attachment":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=1624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=1624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=1624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}