{"id":1522,"date":"2017-03-20T00:03:00","date_gmt":"2017-03-20T00:03:00","guid":{"rendered":"http:\/\/www.fastwebhost.in\/blog\/?p=1522"},"modified":"2019-01-22T11:41:24","modified_gmt":"2019-01-22T11:41:24","slug":"30-linux-find-command-with-examples","status":"publish","type":"post","link":"https:\/\/www.fastwebhost.in\/blog\/30-linux-find-command-with-examples\/","title":{"rendered":"30 Examples for Find Command in Linux"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>\u200bIn Linux when you are working with shell, Find Command in Linux is &nbsp;one of the most useful one where one can check all files\/folders on &nbsp;you server. It helps to search for a specific text string in a file or files. The command sends the specified lines to the standard output device.<\/p>\n<p>Let us see different find commands with variety of filters and parameters.&nbsp;<\/p>\n<h2>Find Commands in linux with Examples\u200b<\/h2>\n<p>\u200b1. This command checks all files in \/home directory with the name fastwebhost.txt<\/p>\n<p>find \/home -name fastwebhost.txt<\/p>\n<p>2. This find command in linux checks all files in current working directory with the name fastwebhost.txt<\/p>\n<p>find . -name \u200bfastwebhost.txt<\/p>\n<p>3. This command will search all files in home directory irrespective to case sensitive.<\/p>\n<p>find \/home -iname FastWebhost.txt\u200b<\/p>\n<p>4. This command checks all directories with a particular name like &#8220;usr&#8221; in root folder<\/p>\n<p>find \/ -type d -name usr\u200b<\/p>\n<p>5. This find command in linux checks all tmp files with file name tmp.php<\/p>\n<p>find \/ -type f -name tmp.php\u200b<\/p>\n<h3>Check files\/folders as per their permissions<\/h3>\n<p>6. The below command can check all &#8220;test.php&#8221; files with 777 permissions<\/p>\n<p>\u200bfind \/ -perm 777 -name test.php<\/p>\n<p>\u200b7. The below find command in linux can check files with SUID bit set with permissions 755<\/p>\n<blockquote><p>&#8220;SUID&#8221; is defined as giving temporary permissions to a user to run a program\/file with the permissions of the file owner rather that the user who runs it.<\/p><\/blockquote>\n<p>find \/ -perm 4755\u200b<\/p>\n<p>8. How to search SGID bit set files with 644 permissions<\/p>\n<blockquote><p>&#8220;SGID&#8221; is nothing but assigning temporary permissions to a user to run a program\/file with the permissions of the file group permissions to become member of that group to execute the file. In simple words users will get file Group&#8217;s permissions when executing a Folder\/file\/program\/command. SGID is similar to SUID.<\/p><\/blockquote>\n<p>find \/ -perm 2644\u200b<\/p>\n<p>9. The below Command checks sticky bit files with permissions 755<\/p>\n<blockquote><p>A Sticky bit is a permission bit that is set on a file or a directory that lets only the owner of the file\/directory or the root user to delete or rename the file. No other user is given privileges to delete the file which was created by any other user.<\/p><\/blockquote>\n<p>\u200bfind \/ -perm 1755<\/p>\n<h3>Using Find command&nbsp;based on users and groups<\/h3>\n<p>10. This command checks all the files with test.txt which is owned by a particular user.<\/p>\n<p>find \/ -user fastwebhost -name test.txt<\/p>\n<p>11. This find command in linux checks all the files with test.txt which is owned by a particular group.<\/p>\n<p>find \/ -group fastweb\u200bhost -name test.txt<\/p>\n<h3>Find command to search the modified date &amp; time of a particular file( In Days)<\/h3>\n<p>12. \u200bThis command search for the files which were modified more than 90 days back<\/p>\n<p>find \/ -ctime +90 test.txt\u200b<\/p>\n<p>13. This command searches all files which were modified exactly 90 days back<\/p>\n<p>find \/ -mtime \u200b90<\/p>\n<p>14. This command searches all files which were access less than 90 days<\/p>\n<p>find \/ -atime -90\u200b<\/p>\n<p>15. This command will search all files which were modified in between two time ranges, like more than 90 days and less than 180 days.<\/p>\n<p>find \/ -mtime +90 -mtime -180\u200b<\/p>\n<h3>Find command to search when the files was modified (Short period, like in minutes\/hours)<\/h3>\n<p>16. This command fiinds all files which were modified less than 45 minutes.<\/p>\n<p>\u200bfind \/ -cmin -45<\/p>\n<p>17. The below command to check all files with last change log if it is exatly below 45 minutes.<\/p>\n<p>find \u200b\/ -mmin 45<\/p>\n<p>18. This command helps you check all files which have been changed more than 45 minutes back.<\/p>\n<p>find \/ -amin +45\u200b<\/p>\n<p>19. It finds all files modified after 6 minutes and below 30 minutes.<\/p>\n<p>find \/ -mmin +6 -mmin -30\u200b<\/p>\n<p>20. Lets see how to check the file which were created after creating test.txt file<\/p>\n<p>\u200bfind \/ -newer test.txt<\/p>\n<h3>Find Command to search files\/folders based on size<\/h3>\n<p>\u200b21. It searches for the files\/folders which are more than 10 bytes in size.<\/p>\n<p>find \/ -size +10c\u200b<\/p>\n<p>22. It finds the file\/folders which were more than 20 kb(kilo bytes) in any of the folder<\/p>\n<p>find \/tmp -size 20k\u200b<\/p>\n<p>23. The following command searches the file\/folder with less than 10MB in a folder<\/p>\n<p>find \/tmp -size -10M\u200b<\/p>\n<p>24. The below command will search all files\/folders which are more than 1GB<\/p>\n<p>find \/\u200b -size +1G<\/p>\n<p>25. To search all empty files in server<\/p>\n<p>find \/ -size 0c<\/p>\n<p>26. Find all the files which are with more than size 50MB and less than 500GB and the owner of the file is test and the file name is fastwebhost.txt in \/fast folder.<\/p>\n<p>find \/fast -size +50M -size -500M -user test -iname fastwebhost.txt<\/p>\n<h3>Executing commands on the files\/folder found with &#8220;find&#8221; command<\/h3>\n<p>\u200bCaution: When using -exec option which you are going to learn below, you should be more cautious. If you don&#8217;t use wisely this can remove\/change anything.<\/p>\n<p>There are some instances when you want to execute commands on the found files with find command. -exec is the option used in find command to execute shell commands directly on found files\/folders. Let\u2019s discuss this with a simple example.<\/p>\n<p>27. \u200bThe below command with -exec option will search \/tmp folder for *pass.* file and list the output on your screen.<\/p>\n<p>find \/tmp -iname *pass.* -exec ls -ld {} ;<\/p>\n<p>28. The below command finds the file test.txt with the fast1 as owner&nbsp;in \/home folder, than it will change the ownership to fast2 by executing the chown command using -exec<\/p>\n<p>find \/home -user fast1 -name test.txt -exec chown fast2.fast2 {} ;\u200b<\/p>\n<p>29. The below command will find the file &#8220;pass.txt&#8221; under \/tmp folder and try to grep the word &#8220;Name&#8221; using executive command.<\/p>\n<p>find \/tmp -iname pass.txt -exec grep &#8220;Name&#8221; {} ;\u200b<\/p>\n<p>30. This command will search for test.txt.db file under the user fast and change the file permission to 755 using -exec option.<\/p>\n<p>find \/var\/named -user fast -name test.txt.db -exec chmod 755 {} ;\u200b<\/p>\n<h3>Conclusion<\/h3>\n<p>\u200bHope this articles helps you get familiar with Find Command in Linux. I will keep adding more commands to this article soon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction \u200bIn Linux when you are working with shell, Find Command in Linux is &nbsp;one of the most useful one where one can check all files\/folders on &nbsp;you server. It helps to search for a specific text string in a file or files. The command sends the specified lines to the standard output device. Let [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":2162,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[22],"tags":[113,110],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1522"}],"collection":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/comments?post=1522"}],"version-history":[{"count":3,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1522\/revisions"}],"predecessor-version":[{"id":4709,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/posts\/1522\/revisions\/4709"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/media\/2162"}],"wp:attachment":[{"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/media?parent=1522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/categories?post=1522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fastwebhost.in\/blog\/wp-json\/wp\/v2\/tags?post=1522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}