{"id":857,"date":"2015-08-18T19:42:31","date_gmt":"2015-08-19T01:42:31","guid":{"rendered":"http:\/\/islascruz.org\/blog\/?p=857"},"modified":"2016-11-29T17:15:40","modified_gmt":"2016-11-29T23:15:40","slug":"find-and-remove-files-with-find","status":"publish","type":"post","link":"https:\/\/islascruz.org\/blog\/2015\/08\/18\/find-and-remove-files-with-find\/","title":{"rendered":"Find (and remove files) with find"},"content":{"rendered":"<p><a href=\"http:\/\/islascruz.org\/blog\/wp-content\/uploads\/2015\/08\/terminal.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-864 size-medium\" src=\"http:\/\/islascruz.org\/blog\/wp-content\/uploads\/2015\/08\/terminal-300x300.png\" alt=\"terminal\" width=\"300\" height=\"300\" srcset=\"https:\/\/islascruz.org\/blog\/wp-content\/uploads\/2015\/08\/terminal-300x300.png 300w, https:\/\/islascruz.org\/blog\/wp-content\/uploads\/2015\/08\/terminal-150x150.png 150w, https:\/\/islascruz.org\/blog\/wp-content\/uploads\/2015\/08\/terminal.png 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>find<\/strong>\u00a0is a great tool to find things, but not only to find them, but to work on them. I have a small collection of music, which I presume at some point will be removed from my computer hard drive (maybe if I can get a new one it won&#8217;t be there at all) because I mostly listen to music from internet and I have a copy of the music in a external hard drive.<\/p>\n<p>Today I imported the folder where the music is to iTunes again, and it created playlists that I don&#8217;t remember to have them before. That is because there were several m3u files there (winamp playlists), there are around 5k files in that directory tree and I don&#8217;t want to spend my time looking for m3u files, so, let the computer do the job.<\/p>\n<p>With find is easy to find files, not by their name but by their type the <em>f<\/em> is for file.<\/p>\n<pre class=\"lang:python decode:1 \" >\nfind . -type f\n<\/pre>\n<p>Ok, but that will include all the &#8220;mp3&#8221; which are files, so if I make use of <em>-iname<\/em> to find by name, \u00a0how can I do the opposite?, well, like in most programming languages, you can negate by using the exclamation symbol <em>!.<\/em><\/p>\n<pre class=\"lang:bash decode:1 \" >\nfind . -type f ! -iname &quot;*mp3&quot;\n<\/pre>\n<p>And add some more extensions.<\/p>\n<pre class=\"lang:bash decode:1 \" >\nfind . -type f ! -iname &quot;*mp3&quot; ! -iname &quot;*ogg&quot; ! -iname &quot;*m4a&quot; ! -iname &quot;*wma&quot;\n<\/pre>\n<p>That will give me all files that are not mp3, ogg, m4a or wma. Then just use the <em>-delete<\/em> parameter to as find to delete them.<\/p>\n<pre class=\"lang:bash decode:1 \" >\nfind . -type f ! -iname &quot;*mp3&quot; ! -iname &quot;*ogg&quot; ! -iname &quot;*m4a&quot; ! -iname &quot;*wma&quot; -delete\n<\/pre>\n<p>And&#8230; they are gone.<\/p>\n<p><strong>How would you do it?. Share it in the comments.<\/strong><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_857\" class=\"pvc_stats all  \" data-element-id=\"857\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/islascruz.org\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>find\u00a0is a great tool to find things, but not only to find them, but to work on them. I have a small collection of music, which I presume at some point will be removed from my computer hard drive (maybe if I can get a new one it won&#8217;t be there at all) because I [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_857\" class=\"pvc_stats all  \" data-element-id=\"857\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/islascruz.org\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":864,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[182,183,34,184],"class_list":["post-857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","tag-bash","tag-find","tag-tips","tag-tricks"],"a3_pvc":{"activated":true,"total_views":2634,"today_views":0},"brizy_media":[],"_links":{"self":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/comments?post=857"}],"version-history":[{"count":9,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/857\/revisions"}],"predecessor-version":[{"id":3132,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/posts\/857\/revisions\/3132"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/media\/864"}],"wp:attachment":[{"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/media?parent=857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/categories?post=857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islascruz.org\/blog\/wp-json\/wp\/v2\/tags?post=857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}