<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Serhii Klochko</title>
    <description>The latest articles on DEV Community by Serhii Klochko (@graceman9).</description>
    <link>https://dev.to/graceman9</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F317581%2Fbcbf1845-5b13-46ec-b44c-02ea99d69da2.jpeg</url>
      <title>DEV Community: Serhii Klochko</title>
      <link>https://dev.to/graceman9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/graceman9"/>
    <language>en</language>
    <item>
      <title>PHP 8.0, 8.1, 8.2, 8.3... what's new?! CheatSheet.</title>
      <dc:creator>Serhii Klochko</dc:creator>
      <pubDate>Thu, 18 Apr 2024 19:49:32 +0000</pubDate>
      <link>https://dev.to/graceman9/php-80-81-82-83-whats-new-cheatsheet-191g</link>
      <guid>https://dev.to/graceman9/php-80-81-82-83-whats-new-cheatsheet-191g</guid>
      <description>&lt;p&gt;The idea of this note is to write down PHP 8+ what's news briefly, so they are visible all at once on a single page. Like a &lt;strong&gt;cheat-sheet&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Keep in mind that these are just the basic features, see each version's link for more details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.php.net/releases/8.0/en.php" rel="noopener noreferrer"&gt;PHP 8.0 What's new&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Named function arguments&lt;/strong&gt; (i.e. &lt;code&gt;arg_name: value&lt;/code&gt;, instead of filling preceding default arguments)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attributes&lt;/strong&gt; (instead of DocBlock comments)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constructor property promotion&lt;/strong&gt; (properties in constructor instead of normal declaration)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Union types&lt;/strong&gt; (i.e. &lt;code&gt;int|string $varname&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Match expression&lt;/strong&gt; (to replace some of &lt;code&gt;switch-case&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nullsafe operator&lt;/strong&gt; (instead of nesteds ifs)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Saner string to number comparisons&lt;/strong&gt; (i.e. &lt;code&gt;0 == 'somestrval' // not true anymore&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistent type errors for internal functions&lt;/strong&gt; (internal functions throws typed exceptions now)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Just-In-Time compilation&lt;/strong&gt; (2x performance in some specific long-running applications)&lt;/li&gt;
&lt;li&gt;and &lt;a href="https://www.php.net/releases/8.0/en.php#consistent-type-errors-for-internal-functions" rel="noopener noreferrer"&gt;more&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.php.net/releases/8.1/en.php" rel="noopener noreferrer"&gt;PHP 8.1 What's new&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Enumerations&lt;/strong&gt; (enums)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Readonly Properties&lt;/strong&gt; (for VO and DTO)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;First-class Callable Syntax&lt;/strong&gt; (to get a reference to any function, i.e. &lt;code&gt;$fn = strlen(...);&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New in initializers&lt;/strong&gt; (for nested attributes)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pure Intersection Types&lt;/strong&gt; (&lt;code&gt;Iterator&amp;amp;Countable $value&lt;/code&gt; but not &lt;code&gt;A&amp;amp;B|C&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never return type&lt;/strong&gt; (to be clear that function returns nothing)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Final class constants&lt;/strong&gt; (cannot override functions and inherit classes)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explicit Octal numeral notation&lt;/strong&gt; &lt;code&gt;// TODO: add some description below&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fibers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Array unpacking support for string-keyed arrays&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;and &lt;a href="https://www.php.net/releases/8.1/en.php#performance_improvements" rel="noopener noreferrer"&gt;more&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.php.net/releases/8.2/en.php" rel="noopener noreferrer"&gt;PHP 8.2 What's new&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Readonly classes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disjunctive Normal Form (DNF) Types&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Allow &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt;, and &lt;code&gt;true&lt;/code&gt; as stand-alone types&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New "Random" extension&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Constants in traits&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deprecate dynamic properties&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;and &lt;a href="https://www.php.net/releases/8.2/en.php#other_new_things" rel="noopener noreferrer"&gt;more&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.php.net/releases/8.3/en.php" rel="noopener noreferrer"&gt;PHP 8.3. What's new&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Typed class constants&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic class constant fetch&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New &lt;code&gt;#[\Override]&lt;/code&gt; attribute&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deep-cloning of readonly properties&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New &lt;code&gt;json_validate()&lt;/code&gt; function&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New &lt;code&gt;Randomizer::getBytesFromString()&lt;/code&gt; method&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New &lt;code&gt;Randomizer::getFloat()&lt;/code&gt; and &lt;code&gt;Randomizer::nextFloat()&lt;/code&gt; methods&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Command line linter supports multiple files&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;and &lt;a href="https://www.php.net/releases/8.3/en.php#other_new_things" rel="noopener noreferrer"&gt;more&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>How to flatten a PHP array</title>
      <dc:creator>Serhii Klochko</dc:creator>
      <pubDate>Thu, 15 Feb 2024 01:13:02 +0000</pubDate>
      <link>https://dev.to/graceman9/how-to-flatten-a-php-array-56no</link>
      <guid>https://dev.to/graceman9/how-to-flatten-a-php-array-56no</guid>
      <description>&lt;p&gt;Here is what I was looking for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;true_flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$parents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$return&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$array&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$k&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$parents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nv"&gt;$parents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$k&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;is_array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$return&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nv"&gt;$return&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;true_flatten&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$return&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;implode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'_'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sample array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'a'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'b'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'c'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value1.1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'d'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value1.2'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="s1"&gt;'e'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value2'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'f'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'j'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'k'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value2.1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'m'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value2.2'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'n'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value2.3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="s1"&gt;'o'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'p'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'some'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'very'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="s1"&gt;'deep'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="s1"&gt;'item'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                        &lt;span class="s1"&gt;'first'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="s1"&gt;'second'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="s1"&gt;'q'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'value5'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// sample data&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"b_c"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value1.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"b_d"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value1.2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"e"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"f_j_k"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value2.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"f_j_m"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value2.2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"f_j_n"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value2.3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"o"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"p_some_very_deep_item_0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"first"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"p_some_very_deep_item_1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"second"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"q"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"value5"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>array</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>How to check directory size in Linux/Ubuntu via command line</title>
      <dc:creator>Serhii Klochko</dc:creator>
      <pubDate>Thu, 25 Jan 2024 14:19:26 +0000</pubDate>
      <link>https://dev.to/graceman9/how-to-check-directory-size-in-linuxubuntu-via-command-line-47ji</link>
      <guid>https://dev.to/graceman9/how-to-check-directory-size-in-linuxubuntu-via-command-line-47ji</guid>
      <description>&lt;p&gt;(Note: It works for MacOS too)&lt;/p&gt;

&lt;p&gt;If you need to check the size of a directory on your computer, it is better to use special tools such as &lt;strong&gt;ncdu&lt;/strong&gt;, &lt;strong&gt;dust&lt;/strong&gt; or &lt;strong&gt;tree&lt;/strong&gt;. I prefer ncdu - it does the job!&lt;/p&gt;

&lt;p&gt;But, it is more common to use CLI if you work with a remote machine, often without a permission to install additional software into it. Then pre-installed tools come to rescue - &lt;strong&gt;du&lt;/strong&gt;. See how I use it below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;du -h .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives us a list of all directories and subdirectories in current directory. That's not what we meant, huh?&lt;br&gt;
Note: The &lt;strong&gt;dot character&lt;/strong&gt; can be replaced with a relative or absolute directory path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;du -sh .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The option &lt;code&gt;-s&lt;/code&gt; stands for summary result. Now we see the entire folder size. But still, how to see each subfolder individually?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;du -sh ./*

# or just:
du -sh *
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here it is! Now we see the size of each subfolder of 1st level.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;du -sh .[^.]* *
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you might want to see hidden folder and files too. A bit more complicated with regular expression.&lt;/p&gt;

&lt;p&gt;Moreover, usually we would like to see result sorted, the largest elements come first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;du -sh * | sort -rh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sort options &lt;code&gt;-r&lt;/code&gt; is for reverse, and &lt;code&gt;-h&lt;/code&gt; is for natural/numeric sort order.&lt;/p&gt;

&lt;p&gt;These are just the basics, please share your favourite method in the comments.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>terminal</category>
      <category>beginners</category>
      <category>command</category>
    </item>
  </channel>
</rss>
