{"id":221,"date":"2012-11-07T16:08:11","date_gmt":"2012-11-07T16:08:11","guid":{"rendered":"http:\/\/vickistan.com\/?p=221"},"modified":"2025-09-18T13:37:02","modified_gmt":"2025-09-18T13:37:02","slug":"find-commands","status":"publish","type":"post","link":"https:\/\/vickistan.com\/?p=221","title":{"rendered":"Useful find Commands"},"content":{"rendered":"\n<p>The find command is very verstile, and I use it all the time. Here are the parameters that I use most often:<br \/><strong>-name<\/strong> &lt;<strong>string<\/strong>&gt; Finds files in specified directory whose name matches (case-sensitive) string<br \/><span style=\"box-sizing: inherit; font-weight: 700;\">-iname<\/span> &lt;<strong>string<\/strong>&gt; Finds files in specified directory whose name matches (case-insensitive) string<br \/><strong>-exec<\/strong> Executes a command on the files found (see ls -l example below)<br \/><strong>-perm &lt;mode&gt;<\/strong> Finds files in specified directory that match the permission mode<br \/><strong>-size<\/strong> Finds files in specified directory<br \/><strong>-print<\/strong> Finds the files and prints out the filename. This is useful in a <code>find . -exec grep<\/code><br \/><strong>-regex<em>&lt;<\/em>pattern<em>&gt;<\/em><\/strong>  Finds files in specified directory with name that matches regular expression pattern.<br \/><strong>-atime &lt;+-&gt;&lt;n&gt;<\/strong> Finds files in specified directory that were accessed less than, more than, or exactly n minutes ago<br \/><strong>-amin &lt;+-&gt;&lt;n&gt;<\/strong> Finds files in the specified directory that were accessed less than, more than, or exactly n minutes ago<br \/><strong>-mmin &lt;+-&gt;&lt;n&gt;<\/strong> Finds files in specified directory that were last modified less than, more than, or exactly n minutes ago<br \/><strong>-mtime &lt;+-&gt;&lt;n&gt;<\/strong> Finds files in specified directory that were last modified less than, more than, or exactly n*24 hours ago<br \/><strong>-type<\/strong> &lt;filetype&gt; Find files in the specified directory of type:<br \/>              b      block (buffered) special<br \/>              c      character (unbuffered) special<br \/>              d      directory<br \/>              p      named pipe (FIFO)<br \/>              f      regular file<br \/>              l      symbolic link; this is never true if the <strong>-L <\/strong>option<br \/>                     or the <strong>-follow <\/strong>option is in effect, unless the<br \/>                     symbolic link is broken.  If you want to search for<br \/>                     symbolic links when <strong>-L <\/strong>is in effect, use <strong>-xtype<\/strong>.<br \/>              s      socket<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Examples:<\/strong><br \/>Find files in current directory that end in <code>.txt<\/code>:<br \/><code>find . -name \"*.txt\"<\/code><br \/><br \/>Find files in current directory that were created within the last hour:<br \/>find . -ctime -60<br \/><br \/>Find 5 largest files<br \/><code>find \/ -type f -exec ls -la {} + 2>\/dev\/null | sort -k5 -rn | head -5<\/code><\/p>\n\n\n\n<p>Find files in current directory not owned by root:<br \/><code>find . \\! -user root -print<\/code><br \/><br \/>Find files in current directory with 0777 permissions and chmod them to 644:<br \/><code>find . -type f -perm 0777 -print -exec chmod 644 {} \\;<\/code><\/p>\n\n\n\n<p>Find files in current directory with owner apache and change to www-data:<br \/><code>find . -user apache -exec chown www-data {} \\;<\/code><br \/><br \/>Find all files in current directory that contain <code>string<\/code> and output their names:<br \/><code>find . -exec grep string {} \\; -print<\/code><\/p>\n\n\n\n<p>Find files in the current directory with ACLs set:<br \/><code>find . -type f -exec ls -l {} \\; | grep -v \"\\+\"<\/code><\/p>\n\n\n\n<p>Find files older than 7 days matching string &#8220;vicki_test2 and move to new directory <br \/><code>mkdir -p \/var\/mitto\/data\/vicki_dir &amp;&amp; find \/var\/mitto\/data\/ -regextype posix-extended -regex '^.*vicki_test2.*\\.[^.]+$' -mtime +7 -exec mv {} \/var\/mitto\/data\/vicki_dir \\;<\/code><\/p>\n\n\n\n<p><br \/><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The find command is very verstile, and I use it all the time. Here are the parameters that I use most often:-name &lt;string&gt; Finds files in specified directory whose name matches (case-sensitive) string-iname &lt;string&gt; Finds files in specified directory whose &hellip; <a href=\"https:\/\/vickistan.com\/?p=221\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=221"}],"version-history":[{"count":13,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":962,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/221\/revisions\/962"}],"wp:attachment":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}