{"id":453,"date":"2009-04-16T20:50:41","date_gmt":"2009-04-16T17:50:41","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=453"},"modified":"2009-05-28T23:02:27","modified_gmt":"2009-05-28T20:02:27","slug":"delete-all-empty-directories-using-xarg","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/","title":{"rendered":"delete all empty directories using xargs"},"content":{"rendered":"<p>I was trying to figure out one 1-liner to delete all empty directories in a tree.<br \/>\nThe following should do it&#8217;s job:<br \/>\n<code>%find -type d -empty | xargs rm -rvf<\/code><\/p>\n<p>BUT! While this works for directories with &#8220;regular&#8221; filenames, it doesn&#8217;t work when there are special characters inside the filename. Consider this for example:<\/p>\n<p><code>%ls -1<br \/>\ntest 1<br \/>\ntest2<br \/>\ntest _ 3<br \/>\n%find -type d -empty<br \/>\n.\/test 1<br \/>\n.\/test2<br \/>\n.\/test _ 3<br \/>\n%find -type d -empty | xargs rm -rvf<br \/>\nremoved directory: `.\/test2'<br \/>\n%find -type d -empty<br \/>\n.\/test 1<br \/>\n.\/test _ 3<br \/>\n<\/code><\/p>\n<p>Only directory &#8220;test2&#8221; was deleted. To delete the rest of the directories when they contain &#8220;special&#8221; characters like whitespace and quotes one needs to modify the command like this:<\/p>\n<p><code>%find -type d -empty -print0 | xargs -0 rm -rvf<br \/>\nremoved directory: `.\/test 1'<br \/>\nremoved directory: `.\/test _ 3 '<\/code><\/p>\n<p>\ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was trying to figure out one 1-liner to delete all empty directories in a tree. The following should do it&#8217;s job: %find -type d -empty | xargs rm -rvf BUT! While this works for directories with &#8220;regular&#8221; filenames, it doesn&#8217;t work when there are special characters inside the filename. Consider this for example: %ls [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[3],"tags":[104,105,595,47,106],"class_list":["post-453","post","type-post","status-publish","format-standard","hentry","category-linux","tag-delete","tag-directory","tag-linux","tag-oneliner","tag-xargs"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"I was trying to figure out one 1-liner to delete all empty directories in a tree. The following should do it&#039;s job: %find -type d -empty | xargs rm -rvf BUT! While this works for directories with &quot;regular&quot; filenames, it doesn&#039;t work when there are special characters inside the filename. Consider this for example: %ls\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"kargig\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#article\",\"name\":\"delete all empty directories using xargs | Into.the.Void.\",\"headline\":\"delete all empty directories using xargs\",\"author\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#organization\"},\"datePublished\":\"2009-04-16T20:50:41+03:00\",\"dateModified\":\"2009-05-28T23:02:27+03:00\",\"inLanguage\":\"en-US\",\"commentCount\":4,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#webpage\"},\"articleSection\":\"Linux, delete, directory, Linux, oneliner, xargs\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/#listItem\",\"name\":\"Linux\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/#listItem\",\"position\":2,\"name\":\"Linux\",\"item\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#listItem\",\"name\":\"delete all empty directories using xargs\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#listItem\",\"position\":3,\"name\":\"delete all empty directories using xargs\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/category\\\/linux\\\/#listItem\",\"name\":\"Linux\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#organization\",\"name\":\"Into.the.Void.\",\"description\":\"Into The Void\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/\",\"sameAs\":[\"https:\\\/\\\/x.com\\\/kargig\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/\",\"name\":\"kargig\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#webpage\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/\",\"name\":\"delete all empty directories using xargs | Into.the.Void.\",\"description\":\"I was trying to figure out one 1-liner to delete all empty directories in a tree. The following should do it's job: %find -type d -empty | xargs rm -rvf BUT! While this works for directories with \\\"regular\\\" filenames, it doesn't work when there are special characters inside the filename. Consider this for example: %ls\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/2009\\\/04\\\/16\\\/delete-all-empty-directories-using-xarg\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/author\\\/site-admin\\\/#author\"},\"datePublished\":\"2009-04-16T20:50:41+03:00\",\"dateModified\":\"2009-05-28T23:02:27+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/\",\"name\":\"Into.the.Void.\",\"description\":\"Into The Void\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.void.gr\\\/kargig\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"delete all empty directories using xargs | Into.the.Void.","description":"I was trying to figure out one 1-liner to delete all empty directories in a tree. The following should do it's job: %find -type d -empty | xargs rm -rvf BUT! While this works for directories with \"regular\" filenames, it doesn't work when there are special characters inside the filename. Consider this for example: %ls","canonical_url":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#article","name":"delete all empty directories using xargs | Into.the.Void.","headline":"delete all empty directories using xargs","author":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author"},"publisher":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/#organization"},"datePublished":"2009-04-16T20:50:41+03:00","dateModified":"2009-05-28T23:02:27+03:00","inLanguage":"en-US","commentCount":4,"mainEntityOfPage":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#webpage"},"isPartOf":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#webpage"},"articleSection":"Linux, delete, directory, Linux, oneliner, xargs"},{"@type":"BreadcrumbList","@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/www.void.gr\/kargig\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/#listItem","name":"Linux"}},{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/#listItem","position":2,"name":"Linux","item":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#listItem","name":"delete all empty directories using xargs"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#listItem","position":3,"name":"delete all empty directories using xargs","previousItem":{"@type":"ListItem","@id":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/#listItem","name":"Linux"}}]},{"@type":"Organization","@id":"https:\/\/www.void.gr\/kargig\/blog\/#organization","name":"Into.the.Void.","description":"Into The Void","url":"https:\/\/www.void.gr\/kargig\/blog\/","sameAs":["https:\/\/x.com\/kargig"]},{"@type":"Person","@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author","url":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/","name":"kargig"},{"@type":"WebPage","@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#webpage","url":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/","name":"delete all empty directories using xargs | Into.the.Void.","description":"I was trying to figure out one 1-liner to delete all empty directories in a tree. The following should do it's job: %find -type d -empty | xargs rm -rvf BUT! While this works for directories with \"regular\" filenames, it doesn't work when there are special characters inside the filename. Consider this for example: %ls","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/#breadcrumblist"},"author":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author"},"creator":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/author\/site-admin\/#author"},"datePublished":"2009-04-16T20:50:41+03:00","dateModified":"2009-05-28T23:02:27+03:00"},{"@type":"WebSite","@id":"https:\/\/www.void.gr\/kargig\/blog\/#website","url":"https:\/\/www.void.gr\/kargig\/blog\/","name":"Into.the.Void.","description":"Into The Void","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.void.gr\/kargig\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"453","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2022-01-04 11:58:20","updated":"2026-10-21 09:41:05","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.void.gr\/kargig\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/\" title=\"Linux\">Linux<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tdelete all empty directories using xargs\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.void.gr\/kargig\/blog\/"},{"label":"Linux","link":"https:\/\/www.void.gr\/kargig\/blog\/category\/linux\/"},{"label":"delete all empty directories using xargs","link":"https:\/\/www.void.gr\/kargig\/blog\/2009\/04\/16\/delete-all-empty-directories-using-xarg\/"}],"views":24151,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=453"}],"version-history":[{"count":4,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/453\/revisions"}],"predecessor-version":[{"id":550,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/453\/revisions\/550"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}