{"id":1198,"date":"2023-11-27T11:23:36","date_gmt":"2023-11-27T16:23:36","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=1198"},"modified":"2023-11-29T16:21:28","modified_gmt":"2023-11-29T21:21:28","slug":"linux-how-to-delete-files-recursively","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/linux-how-to-delete-files-recursively\/","title":{"rendered":"Linux: How to delete files recursively"},"content":{"rendered":"\n<p>The rm command deletes files. To delete a directory that is not empty and its subdirectories, use$ rm -rf directory<\/p>\n\n\n\n<p>However, sometimes you need to remove a specific subdirectory rather than the entire directory and its contents. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">|-- engine<br>|-- mod<br>\u00a0 \u00a0 |-- .svn<br>\u00a0 \u00a0 |-- anytext<br>\u00a0 \u00a0 | \u00a0 \u00a0|-- .svn<br>\u00a0 \u00a0 | \u00a0 \u00a0|-- actions<br>\u00a0 \u00a0 |-- crontrigger<br>\u00a0 \u00a0 | \u00a0 \u00a0|-- .svn<br>\u00a0 \u00a0 | \u00a0 \u00a0|-- views<\/pre>\n\n\n\n<p>We want to delete all .git directories and nothing else. We could manually do rm-r .git for every .git directory but there is an easier and more elegant way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ rm -rf `find . -type d -name .git`<\/code><\/pre>\n\n\n\n<p>find will find all directories names .git and rm \u00a0would delete them and their contents.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The rm command deletes files. To delete a directory that is not empty and its subdirectories, use$ rm -rf directory However, sometimes you need to remove a specific subdirectory rather than the entire directory and its contents. For example: |&#8211; engine|&#8211; mod\u00a0 \u00a0 |&#8211; .svn\u00a0 \u00a0 |&#8211; anytext\u00a0 \u00a0 | \u00a0 \u00a0|&#8211; .svn\u00a0 \u00a0 | [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1203,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[383,381,382],"class_list":["post-1198","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","category-linux","tag-command-line-tips","tag-linux-file-management","tag-recursive-deletion"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=1198"}],"version-history":[{"count":4,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1198\/revisions"}],"predecessor-version":[{"id":1202,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1198\/revisions\/1202"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/1203"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=1198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=1198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=1198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}