{"id":905,"date":"2016-02-12T15:20:13","date_gmt":"2016-02-12T22:20:13","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=905"},"modified":"2022-11-22T05:06:20","modified_gmt":"2022-11-22T05:06:20","slug":"35-practical-examples-of-linux-find-command","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2016\/02\/12\/35-practical-examples-of-linux-find-command\/","title":{"rendered":"35 Practical Examples of Linux Find Command"},"content":{"rendered":"<div class=\"entry-inner\">\n<p>The Linux <strong>Find Command<\/strong> is one of the most important and much used command in Linux sytems. Find command used to search and locate list of files and directories based on conditions you specify for files that match the arguments. Find can be used in variety of conditions like you can find files by <strong>permissions<\/strong>, <strong>users<\/strong>, <strong>groups<\/strong>, <strong>file type<\/strong>, <strong>date<\/strong>, <strong>size<\/strong> and other possible criteria.<\/p>\n<div id=\"attachment_533\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/07\/Linux-Fine-Commands.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-533\" title=\"Linux Find Command\" src=\"http:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/07\/Linux-Fine-Commands.png\" alt=\"Linux Find Command\" data-lazy-loaded=\"true\" width=\"425\" height=\"276\"><\/a><\/p>\n<p class=\"wp-caption-text\">35 Linux Find Commands Examples<\/p>\n<\/div>\n<p>Through this article we are sharing our day-to-day Linux find command experience and its usage in the form of examples. In this article we will show you the most used <strong>35 Find Commands<\/strong> examples in Linux. We have divided the section into <strong>Five<\/strong> parts from basic to advance usage of find command.<br \/>\n<span id=\"more-532\"><\/span><\/p>\n<ol>\n<li><strong>Part I<\/strong>: Basic Find Commands for Finding Files with Names<\/li>\n<li><strong>Part II<\/strong>: Find Files Based on their Permissions<\/li>\n<li><strong>Part III<\/strong>: Search Files Based On Owners and Groups<\/li>\n<li><strong>Part IV<\/strong>: Find Files and Directories Based on Date and Time<\/li>\n<li><strong>Part V<\/strong>: Find Files and Directories Based on Size<\/li>\n<\/ol>\n<div align=\"center\"><strong>Part I \u2013 Basic Find Commands for Finding Files with Names<\/strong><\/div>\n<h4>1. Find Files Using Name in Current Directory<\/h4>\n<p>Find all the files whose name is <strong>tecmint.txt<\/strong> in a current working directory.<\/p>\n<pre><strong># find . -name tecmint.txt<\/strong>\n\n.\/tecmint.txt<\/pre>\n<h4>2. Find Files Under Home Directory<\/h4>\n<p>Find all the files under <strong>\/home<\/strong> directory with name <strong>tecmint.txt<\/strong>.<\/p>\n<pre><strong># find \/home -name tecmint.txt<\/strong>\n\n\/home\/tecmint.txt<\/pre>\n<h4>3. Find Files Using Name and Ignoring Case<\/h4>\n<p><center><\/center>Find all the files whose name is <strong>tecmint.txt<\/strong> and contains both capital and small letters in <strong>\/home<\/strong> directory.<\/p>\n<pre><strong># find \/home -iname tecmint.txt<\/strong>\n\n.\/tecmint.txt\n.\/Tecmint.txt<\/pre>\n<h4>4. Find Directories Using Name<\/h4>\n<p>Find all directories whose name is <strong>Tecmint<\/strong> in <strong>\/<\/strong> directory.<\/p>\n<pre><strong># find \/ -type d -name Tecmint<\/strong>\n\n\/Tecmint<\/pre>\n<h4>5. Find PHP Files Using Name<\/h4>\n<p>Find all <strong>php<\/strong> files whose name is <strong>tecmint.php<\/strong> in a current working directory.<\/p>\n<pre><strong># find . -type f -name tecmint.php<\/strong>\n\n.\/tecmint.php<\/pre>\n<h4>6. Find all PHP Files in Directory<\/h4>\n<p>Find all <strong>php<\/strong> files in a directory.<\/p>\n<pre><strong># find . -type f -name \"*.php\"<\/strong>\n\n.\/tecmint.php\n.\/login.php\n.\/index.php<\/pre>\n<div align=\"center\"><strong>Part II \u2013 Find Files Based on their Permissions<\/strong><\/div>\n<h4>7. Find Files With 777 Permissions<\/h4>\n<p>Find all the files whose permissions are <strong>777<\/strong>.<\/p>\n<pre><strong># find . -type f -perm 0777 -print<\/strong><\/pre>\n<h4>8. Find Files Without 777 Permissions<\/h4>\n<p>Find all the files without permission <strong>777<\/strong>.<\/p>\n<pre><strong># find \/ -type f ! -perm 777<\/strong><\/pre>\n<h4>9. Find SGID Files with 644 Permissions<\/h4>\n<p>Find all the <strong>SGID bit<\/strong> files whose permissions set to <strong>644<\/strong>.<\/p>\n<pre># find \/ -perm 2644<\/pre>\n<h4>10. Find Sticky Bit Files with 551 Permissions<\/h4>\n<p>Find all the <strong>Sticky Bit<\/strong> set files whose permission are <strong>551<\/strong>.<\/p>\n<pre><strong># find \/ -perm 1551<\/strong><\/pre>\n<h4>11. Find SUID Files<\/h4>\n<p>Find all <strong>SUID<\/strong> set files.<\/p>\n<pre><strong># find \/ -perm \/u=s<\/strong><\/pre>\n<h4>12. Find SGID Files<\/h4>\n<p>Find all <strong>SGID<\/strong> set files.<\/p>\n<pre><strong># find \/ -perm \/g+s<\/strong><\/pre>\n<h4>13. Find Read Only Files<\/h4>\n<p>Find all <strong>Read Only<\/strong> files.<\/p>\n<pre><strong># find \/ -perm \/u=r<\/strong><\/pre>\n<h4>14. Find Executable Files<\/h4>\n<p>Find all <strong>Executable<\/strong> files.<\/p>\n<pre><strong># find \/ -perm \/a=x<\/strong><\/pre>\n<h4>15. Find Files with 777 Permissions and Chmod to 644<\/h4>\n<p>Find all <strong>777<\/strong> permission files and use <strong>chmod<\/strong> command to set permissions to <strong>644<\/strong>.<\/p>\n<pre><strong># find \/ -type f -perm 0777 -print -exec chmod 644 {} \\;<\/strong><\/pre>\n<h4>16. Find Directories with 777 Permissions and Chmod to 755<\/h4>\n<p>Find all <strong>777<\/strong> permission directories and use <strong>chmod<\/strong> command to set permissions to <strong>755<\/strong>.<\/p>\n<pre><strong># find \/ -type d -perm 777 -print -exec chmod 755 {} \\;<\/strong><\/pre>\n<h4>17. Find and remove single File<\/h4>\n<p>To find a single file called <strong>tecmint.txt<\/strong> and remove it.<\/p>\n<pre><strong># find . -type f -name \"tecmint.txt\" -exec rm -f {} \\;<\/strong><\/pre>\n<h4>18. Find and remove Multiple File<\/h4>\n<p>To find and remove multiple files such as <strong>.mp3<\/strong> or <strong>.txt<\/strong>, then use.<\/p>\n<pre><strong># find . -type f -name \"*.txt\" -exec rm -f {} \\;<\/strong>\n\nOR\n\n<strong># find . -type f -name \"*.mp3\" -exec rm -f {} \\;<\/strong><\/pre>\n<h4>19. Find all Empty Files<\/h4>\n<p>To file all empty files under certain path.<\/p>\n<pre><strong># find \/tmp -type f -empty<\/strong><\/pre>\n<h4>20. Find all Empty Directories<\/h4>\n<p>To file all empty directories under certain path.<\/p>\n<pre><strong># find \/tmp -type d -empty<\/strong><\/pre>\n<h4>21. File all Hidden Files<\/h4>\n<p>To find all hidden files, use below command.<\/p>\n<pre><strong># find \/tmp -type f -name \".*\"<\/strong><\/pre>\n<div align=\"center\"><strong>Part III \u2013 Search Files Based On Owners and Groups<\/strong><\/div>\n<h4>22. Find Single File Based on User<\/h4>\n<p>To find all or single file called <strong>tecmint.txt<\/strong> under <strong>\/<\/strong> root directory of owner root.<\/p>\n<pre><strong># find \/ -user root -name tecmint.txt<\/strong><\/pre>\n<h4>23. Find all Files Based on User<\/h4>\n<p>To find all files that belongs to user <strong>Tecmint<\/strong> under <strong>\/home<\/strong> directory.<\/p>\n<pre><strong># find \/home -user tecmint<\/strong><\/pre>\n<h4>24. Find all Files Based on Group<\/h4>\n<p>To find all files that belongs to group <strong>Developer<\/strong> under <strong>\/home<\/strong> directory.<\/p>\n<pre><strong># find \/home -group developer<\/strong><\/pre>\n<h4>25. Find Particular Files of User<\/h4>\n<p>To find all <strong>.txt<\/strong> files of user <strong>Tecmint<\/strong> under <strong>\/home<\/strong> directory.<\/p>\n<pre><strong># find \/home -user tecmint -iname \"*.txt\"<\/strong><\/pre>\n<div align=\"center\"><strong>Part IV \u2013 Find Files and Directories Based on Date and Time<\/strong><\/div>\n<h4>26. Find Last 50 Days Modified Files<\/h4>\n<p>To find all the files which are modified <strong>50<\/strong> days back.<\/p>\n<pre><strong># find \/ -mtime 50<\/strong><\/pre>\n<h4>27. Find Last 50 Days Accessed Files<\/h4>\n<p>To find all the files which are accessed <strong>50<\/strong> days back.<\/p>\n<pre><strong># find \/ -atime 50<\/strong><\/pre>\n<h4>28. Find Last 50-100 Days Modified Files<\/h4>\n<p>To find all the files which are modified more than <strong>50<\/strong> days back and less than <strong>100<\/strong> days.<\/p>\n<pre><strong># find \/ -mtime +50 \u2013mtime -100<\/strong><\/pre>\n<h4>29. Find Changed Files in Last 1 Hour<\/h4>\n<p>To find all the files which are changed in last <strong>1 hour<\/strong>.<\/p>\n<pre><strong># find \/ -cmin -60<\/strong><\/pre>\n<h4>30. Find Modified Files in Last 1 Hour<\/h4>\n<p>To find all the files which are modified in last <strong>1 hour<\/strong>.<\/p>\n<pre><strong># find \/ -mmin -60<\/strong><\/pre>\n<h4>31. Find Accessed Files in Last 1 Hour<\/h4>\n<p>To find all the files which are accessed in last <strong>1 hour<\/strong>.<\/p>\n<pre><strong># find \/ -amin -60<\/strong><\/pre>\n<div align=\"center\"><strong>Part V \u2013 Find Files and Directories Based on Size<\/strong><\/div>\n<h4>32. Find 50MB Files<\/h4>\n<p>To find all <strong>50MB<\/strong> files, use.<\/p>\n<pre><strong># find \/ -size 50M<\/strong><\/pre>\n<h4>33. Find Size between 50MB \u2013 100MB<\/h4>\n<p>To find all the files which are greater than <strong>50MB<\/strong> and less than <strong>100MB<\/strong>.<\/p>\n<pre><strong># find \/ -size +50M -size -100M<\/strong><\/pre>\n<h4>34. Find and Delete 100MB Files<\/h4>\n<p>To find all <strong>100MB<\/strong> files and delete them using one single command.<\/p>\n<pre><strong># find \/ -size +100M -exec rm -rf {} \\;<\/strong><\/pre>\n<h4>35. Find Specific Files and Delete<\/h4>\n<p>Find all <strong>.mp3<\/strong> files with more than <strong>10MB<\/strong> and delete them using one single command.<\/p>\n<pre><strong># find \/ -type f -name *.mp3 -size +10M -exec rm {} \\;<\/strong><\/pre>\n<p>That\u2019s it, We are ending this post here, In our next article we will discuss more about other Linux commands in depth with practical examples. Let us know your opinions on this article using our comment section.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Linux Find Command is one of the most important and much used command in Linux sytems. Find command used to search and locate list&hellip; <\/p>\n","protected":false},"author":1,"featured_media":948,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=905"}],"version-history":[{"count":1,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/905\/revisions"}],"predecessor-version":[{"id":951,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/905\/revisions\/951"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media\/948"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}