{"id":1040,"date":"2014-03-28T22:56:36","date_gmt":"2014-03-28T21:56:36","guid":{"rendered":"https:\/\/www.hutsky.cz\/blog\/?p=1040"},"modified":"2014-03-28T22:56:36","modified_gmt":"2014-03-28T21:56:36","slug":"delete-huge-amount-of-files-in-a-directory","status":"publish","type":"post","link":"https:\/\/www.hutsky.cz\/blog\/2014\/03\/delete-huge-amount-of-files-in-a-directory\/","title":{"rendered":"Delete huge amount of files in a directory"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-1043\" alt=\"Hard_Disk\" src=\"https:\/\/www.hutsky.cz\/blog\/wp-content\/uploads\/Hard_Disk.png\" width=\"180\" height=\"180\" srcset=\"https:\/\/www.hutsky.cz\/blog\/wp-content\/uploads\/Hard_Disk.png 180w, https:\/\/www.hutsky.cz\/blog\/wp-content\/uploads\/Hard_Disk-150x150.png 150w\" sizes=\"auto, (max-width: 180px) 100vw, 180px\" \/>I had this peculiar problem &#8211; one of my virtual hosts had a custom tmp directory where sessions were stored and not deleted for a long time. When I found out, the number of files in there already posed a big problem because commands like <em>ls<\/em> or <em>rm *<\/em> failed due to a limit to * expansion wildcard. My next thought was to use <em>find<\/em> to get rid of them:<\/p>\n<pre>find . -type f -delete<\/pre>\n<p>which worked just fine, the only problem being that it was so resource-hungry that the load average would soar skywards &#8211; not an option on a live system.<\/p>\n<p>The solution was to use <em>ionice<\/em>, which can tell the process to proceed only when there is free IO time available (the option <em>-c 3<\/em>).<\/p>\n<pre>find . -type f -exec ionice -c 3 rm {} \\;<\/pre>\n<p>The action took much longer, of course, but the load never went higher than just a little bit above 1.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had this peculiar problem &#8211; one of my virtual hosts had a custom tmp directory where sessions were stored and not deleted for a long time. When I found out, the number of files in there already posed a &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.hutsky.cz\/blog\/2014\/03\/delete-huge-amount-of-files-in-a-directory\/\"> <span class=\"screen-reader-text\">Delete huge amount of files in a directory<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,22],"tags":[10,18,13],"class_list":["post-1040","post","type-post","status-publish","format-standard","hentry","category-operatingsystems","category-web-related","tag-debian","tag-linux","tag-os"],"_links":{"self":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts\/1040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/comments?post=1040"}],"version-history":[{"count":4,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts\/1040\/revisions"}],"predecessor-version":[{"id":1044,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts\/1040\/revisions\/1044"}],"wp:attachment":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/media?parent=1040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/categories?post=1040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/tags?post=1040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}