{"id":132,"date":"2022-05-13T05:04:45","date_gmt":"2022-05-13T05:04:45","guid":{"rendered":"http:\/\/checkmateq.com\/blog\/?p=132"},"modified":"2023-08-07T17:35:34","modified_gmt":"2023-08-07T17:35:34","slug":"linux-find-commands","status":"publish","type":"post","link":"https:\/\/www.checkmateq.com\/blog\/linux-find-commands","title":{"rendered":"Linux find command use cases"},"content":{"rendered":"<p>The Linux &#8220;find&#8221; command helps to locate and manage files and directories based on search options like file type, name, size, permissions, created time, edited time, based on created user, etc.<\/p>\n<p>We can also combine &#8220;find&#8221; with &#8220;-exec&#8221; to perform actions on the results of the find command, like changing permissions, copying the files, moving the files, deleting the files, to manage infrastructure operations.<\/p>\n<p><strong>The find command&#8217;s basic syntax<\/strong><\/p>\n<pre>find {path} {name-of-file or dir-to-search} {action-to-take}<\/pre>\n<p><b>path:<\/b> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0specific location or directory to search for.\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <b>name-of-file<\/b>:\u00a0\u00a0 \u00a0 \u00a0 \u00a0\u00a0file name to search for.\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <b>action-to-take:<\/b>\u00a0\u00a0 \u00a0\u00a0subsequent action to perform such as:\u00a0\u00a0copy, move, delete.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre>find \/home\/aksshaaynalmas -name *.txt<\/pre>\n<p>The above given find command searches for all (*) the files with a &#8220;.txt&#8221; extension in the &#8220;<strong>\/home\/aksshaaynalmas<\/strong>&#8221; location, as mentioned in the following output.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-139\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find1-300x62.jpeg\" alt=\"\" width=\"474\" height=\"98\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find1-300x62.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find1.jpeg 687w\" sizes=\"(max-width: 474px) 85vw, 474px\" \/><\/p>\n<p><strong>Example: 2<\/strong><\/p>\n<p><strong>Syntax to find<\/strong> <b>files or directory from current location using Linux find command<\/b><\/p>\n<p>You can use &#8220;.&#8221; instead of mentioning the path &#8220;.&#8221; means current location. Sometimes we need to look for files or directories in the same location. We can use options <b>&#8220;f&#8221;<\/b>\u00a0for files and\u00a0<b>&#8220;d&#8221;<\/b>\u00a0for directories with the find command. For instance, if you have a directory and a file named &#8220;Books,&#8221; you can use it for the directory.<\/p>\n<pre>find . -name Books -type d<\/pre>\n<p>for file.<\/p>\n<pre>find . -name Books -type f<\/pre>\n<p><strong>Example 3:<\/strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <strong>How to find files or directories based on their size using Linux find command<\/strong><\/p>\n<p>You can use the &#8220;find&#8221; command to find all files or directories that are smaller, equal, or greater than a certain size, or empty. You can use the appropriate size format depending on the type of files or directories you are searching for.<\/p>\n<ul>\n<li>To find files which are of certain size(below will command search for file size equal to 10Megabytes)\n<pre>find . -size 10M<\/pre>\n<\/li>\n<li>To find files which are greater than certain size, here command will search for files which are greater than 2M in size.\n<pre>find . -size +2M<\/pre>\n<\/li>\n<li>To find files which are lesser than certain size, here command will search for files which are lesser than 2M in size.\n<pre>find .\/ -size -2M<\/pre>\n<\/li>\n<li>To find the files of size within a specific range such as between 20M and 200 M.\n<pre>find . -size -20M -size +200M<\/pre>\n<\/li>\n<li>To find empty files\n<pre>find .\/ -type f -size 0<\/pre>\n<\/li>\n<\/ul>\n<p><strong>Example 4:<\/strong><\/p>\n<p><strong>How to search files or directories by timestamp or age using Linux find command<\/strong><\/p>\n<ul>\n<li>To get a list of files between two specific dates\n<pre>find . -type f -newermt 2021-08-01 ! -newermt 2022-05-13<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-201\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/by-date-300x100.jpeg\" alt=\"\" width=\"594\" height=\"198\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/by-date-300x100.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/by-date-1024x342.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/by-date-768x256.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/by-date-1536x513.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/by-date-1200x401.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/by-date.jpeg 1920w\" sizes=\"(max-width: 594px) 85vw, 594px\" \/><\/li>\n<li>Finding files or directories based on modification time, This command will search for files that have been modified in the last 10 hours.\n<pre> find . -mtime -10 -type f<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-202\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/last-10-300x86.jpeg\" alt=\"\" width=\"590\" height=\"169\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/last-10-300x86.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/last-10-1024x294.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/last-10-768x220.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/last-10-1536x441.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/last-10-1200x344.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/last-10.jpeg 1920w\" sizes=\"(max-width: 590px) 85vw, 590px\" \/><br \/>\nThis command will search for directories which are modified within last 5 days<\/p>\n<pre>    find . -mtime -5 -type d<\/pre>\n<\/li>\n<li>To find the files based on date or time accessed, this allows you to find\u00a0 files that have been or haven\u2019t been accessed within a specific period of time.<\/li>\n<li>To get\u00a0 files that are not\u00a0 accessed within the last 5 days.\n<pre>find \/home -atime +5<\/pre>\n<\/li>\n<li>To get files that are accessed exactly 5 days ago.\n<pre>find \/home -atime 5<\/pre>\n<\/li>\n<li>To get the files accessed within last 5 days.\n<pre>find \/home -atime -5<\/pre>\n<\/li>\n<\/ul>\n<p><strong>Example 4:<\/strong><\/p>\n<p>Lets see how we can use find command to search for the files and directories based on the users and permissions<\/p>\n<ul>\n<li>To get files with a specific permission\n<pre>find -perm 765<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-203\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-perm-300x38.jpeg\" alt=\"\" width=\"568\" height=\"72\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-perm-300x38.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-perm-1024x131.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-perm-768x98.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-perm-1536x197.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-perm-1200x154.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-perm.jpeg 1920w\" sizes=\"(max-width: 568px) 85vw, 568px\" \/><\/li>\n<li>To get files owned by a specific user\n<pre>find\u00a0 \/home -user\u00a0 aksshaay<\/pre>\n<\/li>\n<li>To get\u00a0 specific files owned by a specific user\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;prefind \/home -user aksshaaynalmas -iname &#8220;*.txt&#8221;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <img loading=\"lazy\" class=\"alignnone wp-image-207\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/user1-300x108.jpeg\" alt=\"\" width=\"572\" height=\"206\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/user1-300x108.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/user1-1024x370.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/user1-768x278.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/user1-1536x555.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/user1-1200x434.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/user1.jpeg 1920w\" sizes=\"(max-width: 572px) 85vw, 572px\" \/><\/li>\n<\/ul>\n<p><strong>Example 5:<\/strong><\/p>\n<p>Searching and listing files and directories along with their permissions<\/p>\n<pre>find -name \".txt\" | ls -l<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-204\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/findpoerm2-300x44.jpeg\" alt=\"\" width=\"682\" height=\"100\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/findpoerm2-300x44.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/findpoerm2-1024x151.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/findpoerm2-768x114.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/findpoerm2-1536x227.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/findpoerm2-1200x178.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/findpoerm2.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><br \/>\nwe will look at how you can act on the files that are results of find command<\/p>\n<p>Using &#8220;find&#8221; command to search files and changing their permissions<\/p>\n<pre>find . -name \"*.txt\" -type f -exec chmod 755 {} \\;<\/pre>\n<p>Lets try this command on these files<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-205\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod1-300x39.jpeg\" alt=\"\" width=\"692\" height=\"90\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod1-300x39.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod1-1024x133.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod1-768x100.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod1-1536x199.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod1-1200x156.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod1.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>output:\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <img loading=\"lazy\" class=\"alignnone wp-image-206\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod2-300x44.jpeg\" alt=\"\" width=\"695\" height=\"102\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod2-300x44.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod2-1024x149.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod2-768x112.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod2-1536x224.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod2-1200x175.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/chmod2.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Searching and copying a files to a directory using find command<\/p>\n<pre>find . -name 'one.txt' -exec cp {} \/copied-files \\;<\/pre>\n<p>this command finds file named &#8220;one.txt&#8221; and copies it to the directory named copied-files<\/p>\n<p>finding files and moving based on the age<\/p>\n<pre>find . -type f -name '*.py' -mtime -1 -exec mv {} copied-files \\;<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-208\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-mv-300x55.jpeg\" alt=\"\" width=\"693\" height=\"127\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-mv-300x55.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-mv-1024x189.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-mv-768x142.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-mv-1536x283.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-mv-1200x221.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-mv.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>finding and deleting files and directories using &#8220;find&#8221; command and -exec.<\/p>\n<pre>find . -type f -name \"*.txt\" -exec rm -f {} \\;<\/pre>\n<p>This command will search and remove all the files with the extension &#8220;.txt&#8221;<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-209\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rm-300x115.jpeg\" alt=\"\" width=\"702\" height=\"269\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rm-300x115.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rm-1024x394.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rm-1536x591.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rm-1200x462.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rm.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><br \/>\nTo find and delete directories<\/p>\n<pre>find . -type d -name \"copied-files\" -exec rm -rf {} \\;<\/pre>\n<p>This command finds and removes a directory named copied-files<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-210\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rmdir-300x115.jpeg\" alt=\"\" width=\"634\" height=\"243\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rmdir-300x115.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rmdir-1024x393.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rmdir-768x295.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rmdir-1536x590.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rmdir-1200x461.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/find-rmdir.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><br \/>\n<strong>Example 6:<\/strong><\/p>\n<p>Using find command for searching and deleting files\u00a0 based on age.<\/p>\n<pre>find . -type f -name '*.txt' -mtime +1 -exec rm {} \\;<\/pre>\n<p>This command deletes all the files with extension &#8220;*.txt&#8221; which are older than 1 day.<\/p>\n<p>Using find command to find and delete directories .<\/p>\n<pre>find . -type d -name dirz -exec rm -rf {} \\;<\/pre>\n<p>This command deletes the directory named dirz<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-211\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-300x65.jpeg\" alt=\"\" width=\"646\" height=\"140\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-300x65.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-1024x221.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-768x166.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-1536x331.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-1200x259.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><br \/>\nOutput:<br \/>\n<img loading=\"lazy\" class=\"alignnone wp-image-212\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-o-300x45.jpeg\" alt=\"\" width=\"640\" height=\"96\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-o-300x45.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-o-1024x152.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-o-768x114.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-o-1536x228.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-o-1200x178.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir-o.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><br \/>\nUsing find command to delete empty files and directories.<\/p>\n<pre>find . -type f -size 0 -exec rm -f {} \\;<\/pre>\n<p>This command removes all the empty files in present working directory<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-213\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-empt-300x107.jpeg\" alt=\"\" width=\"634\" height=\"226\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-empt-300x107.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-empt-1024x364.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-empt-768x273.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-empt-1536x546.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-empt-1200x427.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-empt.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<pre>find -type d -empty -exec rmdir {} \\;<\/pre>\n<p>This command removes empty directories.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-216\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir1-300x87.jpeg\" alt=\"\" width=\"648\" height=\"188\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir1-300x87.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir1-1024x297.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir1-768x222.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir1-1536x445.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir1-1200x348.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir1.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><br \/>\nOutput:<br \/>\n<img loading=\"lazy\" class=\"alignnone wp-image-215\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir2-300x65.jpeg\" alt=\"\" width=\"651\" height=\"141\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir2-300x65.jpeg 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir2-1024x221.jpeg 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir2-768x166.jpeg 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir2-1536x332.jpeg 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir2-1200x259.jpeg 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/rm-dir2.jpeg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Please connect with us get Cloud <a href=\"https:\/\/www.checkmateq.com\/devops-engineering\">DevOps<\/a> Infrastructure solutions<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Linux &#8220;find&#8221; command helps to locate and manage files and directories based on search options like file type, name, size, permissions, created time, edited time, based on created user, etc. We can also combine &#8220;find&#8221; with &#8220;-exec&#8221; to perform actions on the results of the find command, like changing permissions, copying the files, moving &hellip; <a href=\"https:\/\/www.checkmateq.com\/blog\/linux-find-commands\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Linux find command use cases&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":254,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[7,11,8,9,10],"_links":{"self":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/132"}],"collection":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":18,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"predecessor-version":[{"id":4356,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions\/4356"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media\/254"}],"wp:attachment":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}