<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Shell Programming on entangledDEV</title>
        <link>/tags/shell-programming/</link>
        <description>Recent content in Shell Programming on entangledDEV</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <lastBuildDate>Sun, 01 Feb 2026 00:09:25 -0600</lastBuildDate><atom:link href="/tags/shell-programming/index.xml" rel="self" type="application/rss+xml" /><item>
            <title>Deleting Duplicates Subdirectories and Content</title>
            <link>/p/deleting-duplicates-subdirectories-and-content/</link>
            <pubDate>Fri, 22 Dec 2023 01:13:31 +0000</pubDate>
            <guid>/p/deleting-duplicates-subdirectories-and-content/</guid>
            <description>&lt;p&gt;The other day, I encountered an issue involving three directories, and two of them contained a subdirectory with the same name (target).&lt;/p&gt;&#xA;&lt;p&gt;My goal is to delete the target subdirectories in all places with a single command, and here&amp;rsquo;s the solution I found.&lt;/p&gt;&#xA;&lt;p&gt;&#xA;    &lt;img src=&#34;/posts/delete-duplicates-subdirectories/directory-tree.png&#34;&#xA;        loading=&#34;lazy&#34;&#xA;        &#xA;            alt=&#34;directory tree&#34;&#xA;        &#xA;    &gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;using-the-terminal-to-delete-multiple-directories&#34;&gt;&lt;a href=&#34;#using-the-terminal-to-delete-multiple-directories&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Using the terminal to delete multiple directories.&#xA;&lt;/h2&gt;&lt;p&gt;There is an useful command called &lt;code&gt;find&lt;/code&gt;, this command is used to traverse nested directories and evaluate an expression for each element.&lt;/p&gt;&#xA;&lt;p&gt;We can use &lt;code&gt;find&lt;/code&gt; to delete files or directories, here is the command:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;find . -type d -name &lt;span class=&#34;s2&#34;&gt;&amp;#34;target&amp;#34;&lt;/span&gt; -exec rm -rf &lt;span class=&#34;o&#34;&gt;{}&lt;/span&gt; +&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;understanding-the-command&#34;&gt;&lt;a href=&#34;#understanding-the-command&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Understanding the command&#xA;&lt;/h2&gt;&lt;p&gt;This command is easy to grasp, first we have &lt;code&gt;.&lt;/code&gt;, this is telling &lt;code&gt;find&lt;/code&gt; to start traversing in the current directory.&lt;/p&gt;&#xA;&lt;p&gt;Next we have &lt;code&gt;-type&lt;/code&gt;, this argument allows to select a a specific valid type.&lt;/p&gt;&#xA;&lt;p&gt;The valid types are listed below:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;b&lt;/strong&gt;: block special&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;c&lt;/strong&gt;: character special&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;d&lt;/strong&gt;: directory&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;f&lt;/strong&gt;: regular file&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;l&lt;/strong&gt;: symbolic link&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;p&lt;/strong&gt;: FIFO&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;s&lt;/strong&gt;: socket&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Since we need to find an specific directory we use &lt;code&gt;d&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Next it&amp;rsquo;s &lt;code&gt;-name&lt;/code&gt;, we need to give the string that contains the name we are searching for. In our case we are looking for the directories named &lt;code&gt;&amp;quot;target&amp;quot;&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The last part of the command, &lt;code&gt;-exec&lt;/code&gt;, is telling what to do once we find a valid element. In this case we want to delete all the found occurrences, so we&amp;rsquo;re passing &lt;code&gt;rm -rf&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;{}&lt;/code&gt; is just telling that we need to use the current element&amp;rsquo;s name, and &lt;code&gt;+&lt;/code&gt; is used to terminate the &lt;code&gt;-exec&lt;/code&gt; part.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;&lt;a href=&#34;#conclusion&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Conclusion&#xA;&lt;/h2&gt;&lt;p&gt;By using this simple command we can find and delete subdirectories in an easy and convenient way, which I find to be faster than using the GUI.&lt;/p&gt;&#xA;&lt;p&gt;I hope this simple tutorial can help you to solve these kind of problems.&lt;/p&gt;&#xA;</description>
        </item></channel>
</rss>
