{"id":11563,"date":"2024-04-03T20:44:27","date_gmt":"2024-04-03T18:44:27","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=11563"},"modified":"2024-04-03T20:44:28","modified_gmt":"2024-04-03T18:44:28","slug":"3-ways-to-delete-all-files-in-a-directory-except-one-or-few-files-with-extensions","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2024\/04\/03\/3-ways-to-delete-all-files-in-a-directory-except-one-or-few-files-with-extensions\/","title":{"rendered":"3 Ways to Delete All Files in a Directory Except One or Few Files with Extensions"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The different extended pattern matching operators are listed below, where <strong>pattern-list<\/strong> is a list containing one or more filenames, separated using the <code class=\"\" data-line=\"\">|<\/code> character:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code class=\"\" data-line=\"\">*(pattern-list)<\/code> \u2013 matches zero or more occurrences of the specified patterns<\/li>\n\n\n\n<li><code class=\"\" data-line=\"\">?(pattern-list)<\/code> \u2013 matches zero or one occurrence of the specified patterns<\/li>\n\n\n\n<li><strong>+(pattern-list)<\/strong> \u2013 matches one or more occurrences of the specified patterns<\/li>\n\n\n\n<li><code class=\"\" data-line=\"\">@(pattern-list)<\/code> \u2013 matches one of the specified patterns<\/li>\n\n\n\n<li><code class=\"\" data-line=\"\">!(pattern-list)<\/code> \u2013 matches anything except one of the given patterns<\/li>\n<\/ol>\n\n\n\n<p>To use them, enable the <strong>extglob<\/strong> shell option as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># shopt -s extglob\n<\/pre>\n\n\n\n<p><strong>1.<\/strong> To delete all files in a directory except filename, type the command below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ rm -v !(\"filename\")\n<\/pre>\n\n\n\n<figure id=\"attachment_23184\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-23184\"><figcaption id=\"caption-attachment-23184\" class=\"wp-caption-text\">Delete All Files Except One File in Linux<\/figcaption><\/figure>\n\n\n\n<p><strong>2.<\/strong> To delete all files with the exception of <strong>filename1<\/strong> and <strong>filename2<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ rm -v !(\"filename1\"|\"filename2\") \n<\/pre>\n<cite>Source: <em><a href=\"https:\/\/www.tecmint.com\/delete-all-files-in-directory-except-one-few-file-extensions\/\">3 Ways to Delete All Files in a Directory Except One or Few Files with Extensions<\/a><\/em><\/cite><\/blockquote>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2024\/04\/03\/3-ways-to-delete-all-files-in-a-directory-except-one-or-few-files-with-extensions\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"quote","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"federated","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[278],"tags":[298],"class_list":["post-11563","post","type-post","status-publish","format-quote","hentry","category-tricks","tag-shell","post_format-post-format-quote"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-30v","jetpack-related-posts":[{"id":9512,"url":"https:\/\/monodes.com\/predaelli\/2022\/07\/25\/design-patterns-with-python-for-machine-learning-engineers-abstract-factory\/","url_meta":{"origin":11563,"position":0},"title":"Design Patterns with Python for Machine Learning Engineers: Abstract Factory","author":"Paolo Redaelli","date":"2022-07-25","format":false,"excerpt":"Photo by Omar Flores on\u00a0UnsplashLearn how you can structure your code by adopting design\u00a0patternsIntroductionA pattern describes a frequently recurring problem and proposesa possible solution in terms of class\/object organization thatgenerally found to be effective in solving the problem itself.Design Patterns are characterized by four main elements:Name: mnemonic reference that allows\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10190,"url":"https:\/\/monodes.com\/predaelli\/2023\/01\/06\/a-collection-of-popular-layouts-and-patterns-made-with-css-css-layout\/","url_meta":{"origin":11563,"position":1},"title":"A collection of popular layouts and patterns made with CSS &#8211; CSS Layout","author":"Paolo Redaelli","date":"2023-01-06","format":false,"excerpt":"A collection of popular layouts and patterns made with CSS - CSS Layout","rel":"","context":"In &quot;Web&quot;","block_context":{"text":"Web","link":"https:\/\/monodes.com\/predaelli\/category\/web\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":11857,"url":"https:\/\/monodes.com\/predaelli\/2024\/08\/13\/huge-chances\/","url_meta":{"origin":11563,"position":2},"title":"Huge chances?","author":"Paolo Redaelli","date":"2024-08-13","format":false,"excerpt":"I know I know the Observer Pattern. I just wanted to be sure what was the best practice in Python. I found this: Risky Implementations: If the pattern is not implemented carefully, there are huge chances that you will end up with large complexity code. From https:\/\/www.geeksforgeeks.org\/observer-method-python-design-patterns\/ With all the\u2026","rel":"","context":"In &quot;Fun&quot;","block_context":{"text":"Fun","link":"https:\/\/monodes.com\/predaelli\/category\/fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2024\/01\/The-what.webp?fit=635%2C517&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2024\/01\/The-what.webp?fit=635%2C517&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2024\/01\/The-what.webp?fit=635%2C517&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3570,"url":"https:\/\/monodes.com\/predaelli\/2017\/12\/11\/artist-releases-300-printable-dd-miniature-patterns-for-free-geek-and-sundry\/","url_meta":{"origin":11563,"position":3},"title":"Artist Releases 300 Printable D&#038;D Miniature Patterns. For Free. | Geek and Sundry","author":"Paolo Redaelli","date":"2017-12-11","format":false,"excerpt":"","rel":"","context":"In &quot;Role Play Games&quot;","block_context":{"text":"Role Play Games","link":"https:\/\/monodes.com\/predaelli\/category\/games\/role-play-games\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":11554,"url":"https:\/\/monodes.com\/predaelli\/2024\/04\/03\/how-to-replace-string-in-bash-5-methods-linuxsimply\/","url_meta":{"origin":11563,"position":4},"title":"How to Replace String in Bash? [5 Methods] &#8211; LinuxSimply","author":"Paolo Redaelli","date":"2024-04-03","format":"quote","excerpt":"In bash scripting, the replacement of string is important because it allows you to modify a variable and the text of a file. It also helps in file and text processing and to validate user input. To replace a string in bash, check the following methods: Using Parameter expansion: ${String\/pattern\/replacement}\u2026","rel":"","context":"In &quot;Tricks&quot;","block_context":{"text":"Tricks","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/tricks\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":11063,"url":"https:\/\/monodes.com\/predaelli\/2023\/12\/24\/blogvi-wordpress-theme-wordpress-org\/","url_meta":{"origin":11563,"position":5},"title":"Blogvi &#8211; WordPress theme | WordPress.org","author":"Paolo Redaelli","date":"2023-12-24","format":false,"excerpt":"A child theme of Bloglo, Blogvi offers a boxed width design with a distinctive background color and a pattern image. This theme showcases a horizontal blog list style and provides users with extensive customization options for color and typography adjustments.Blogvi is lightweight, moderate and customizable News Magazine WordPress theme. You'll\u2026","rel":"","context":"In &quot;Wordpress&quot;","block_context":{"text":"Wordpress","link":"https:\/\/monodes.com\/predaelli\/category\/wordpress\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/11563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=11563"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/11563\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=11563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=11563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=11563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}