{"id":5,"date":"2007-08-05T03:23:35","date_gmt":"2007-08-04T19:23:35","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/?p=5"},"modified":"2007-08-05T03:23:35","modified_gmt":"2007-08-04T19:23:35","slug":"most-common-unix-find-command","status":"publish","type":"post","link":"https:\/\/www.sysadmindayph.com\/blog\/most-common-unix-find-command\/","title":{"rendered":"Most Common UNIX Find Command"},"content":{"rendered":"<p>The <em>find<\/em> command is the most useful command on a UNIX box. System administrators use this powerful utility frequently.<\/p>\n<p>Presented here, ladies and gentlemen, are the most commonly used &#8216;find&#8217; options.<\/p>\n<p>(Let&#8217;s add more as time goes on, alright?)<\/p>\n<p>Find a file or directory<br \/>\n# find . -name TEMP -print<br \/>\nor<br \/>\n# find . -name TEMP -exec echo {} \\;<\/p>\n<p>Find core files in this directory tree and remove them<br \/>\n# find .  -name &#8220;core&#8221; -exec rm -f {} \\;<\/p>\n<p>Find junk directories and remove their contents recursively<br \/>\n# find .  -name &#8220;junk&#8221; -exec rm -rf {} \\;<\/p>\n<p><!--more--><\/p>\n<p>Find a pattern in a file using the recursive grep (ignore case)<br \/>\n# find . -type f | xargs grep -i <span style=\"font-style: italic\">MYPATTERN<\/span><\/p>\n<p>Find files modified in the past 7 days<span style=\"font-style: italic\"><br \/>\n<\/span># find . -mtime -7 -type f<\/p>\n<p>Find files owned by a particular user<br \/>\n# find . -user esofthub<\/p>\n<p>Find all your writable directories and list them<br \/>\n# find . -perm -0777 -type d -ls<br \/>\nor<br \/>\n# find . -type d -perm 777 -print<\/p>\n<p>Find all your writable files and list them<br \/>\n# find . -perm -0777 -type f -ls<br \/>\nor<br \/>\n#find . -type f -perm 777 -print<\/p>\n<p>Find large file sizes and list them<br \/>\n# find . -type f -size +1000 -ls<br \/>\nor<br \/>\n# find . -type f -size +1000 -print<\/p>\n<p>Find how many directories are in a path (counts current directory)<br \/>\n# find . -type d -exec basename {} \\; | wc -l<br \/>\n53<\/p>\n<p>Find how many files are in a path<br \/>\n# find . -type f -exec basename {} \\; | wc -l<br \/>\n120<\/p>\n<p>Find all my pipe files and change their permissions to all writable<br \/>\n# find . -name &#8220;pipe*&#8221; -exec chmod 666 {} \\;<\/p>\n<p>Find files that were modified 7 days ago and archive<br \/>\n# find . -type f -mtime 7 | xargs tar -cvf `date &#8216;+%d%m%Y&#8217;_archive.tar`<br \/>\n<span style=\"font-family: monospace\"><\/span><br \/>\nFind files that were modified more than 7 days ago and archive<br \/>\n# find . -type f -mtime +7 | xargs tar -cvf `date &#8216;+%d%m%Y&#8217;_archive.tar`<\/p>\n<p>Find files that were modified less than 7 days ago and archive<br \/>\n# find . -type f -mtime -7 | xargs tar -cvf `date &#8216;+%d%m%Y&#8217;_archive.tar`<\/p>\n<p>Find files that were modified more than 7 days ago but less than 14 days ago and archive<br \/>\n# find . -type f -mtime +7 -mtime -14 | xargs tar -cvf `date &#8216;+%d%m%Y&#8217;_archive.tar`<\/p>\n<p>Find files in two different directories having the &#8220;test&#8221; string and list them<br \/>\n# find esofthub esoft -name &#8220;*test*&#8221; -type f -ls<\/p>\n<p>Find files in two different directories having the &#8220;test&#8221; string and list them<br \/>\n# find esofthub esoft -name &#8220;*test*&#8221; -type f -ls<\/p>\n<p>Find files in two different directories having the &#8220;test&#8221; string and count them<br \/>\n# find esofthub esoft -name &#8220;*test*&#8221; -type f -ls | wc -l<br \/>\n12<\/p>\n<p>Find files and directories newer than CompareFile<br \/>\n# find . -newer <span style=\"font-style: italic\">CompareFile <\/span>-print<\/p>\n<p>Find files and directories older than CompareFile<br \/>\n# find .  ! -newer <span style=\"font-style: italic\">CompareFile <\/span>-print<\/p>\n<p>Find files and directories but don&#8217;t traverse a particular directory<br \/>\n# find . -name RAID -prune -o -print<\/p>\n<p>Find all the files in the current directory<br \/>\n# find *  -type f -print -o -type d -prune<\/p>\n<p>Find an inode and remove<br \/>\n# find . -inum <span style=\"font-style: italic\">968746 <\/span>-exec rm -i {}  \\;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The find command is the most useful command on a UNIX box. System administrators use this powerful utility frequently. Presented here, ladies and gentlemen, are the most commonly used &#8216;find&#8217; options. (Let&#8217;s add more as &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,8,3],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-solaris","category-tips","category-unix"],"_links":{"self":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":0,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}