Use du to list size of top 20 largest folders/files in current directory recursively in bytes and human...

What are the problems in teaching guitar via Skype?

Why would Lupin kill Pettigrew?

Thousands and thousands of words

Beginner's snake game using PyGame

What does "tea juice" mean in this context?

Is a hash a zero-knowledge proof?

What was this black-and-white film set in the Arctic or Antarctic where the monster/alien gets fried in the end?

Rotated Position of Integers

Is having a hidden directory under /etc safe?

How to make the POV character sit on the sidelines without the reader getting bored

Is there a rule that prohibits us from using 2 possessives in a row?

Is floating in space similar to falling under gravity?

Modern approach to radio buttons

Possible nonclassical ion from a bicyclic system

Where can I find the list of all tendons in the human body?

How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?

If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?

The deliberate use of misleading terminology

Can a helicopter mask itself from Radar?

Could IPv6 make NAT / port numbers redundant?

How to properly maintain eye contact with people that have distinctive facial features?

When a current flow in an inductor is interrupted, what limits the voltage rise?

Term for checking piece whose opponent daren't capture it

What are the benefits of cryosleep?



Use du to list size of top 20 largest folders/files in current directory recursively in bytes and human readable format


How do you sort du output by size?A standard tool to convert a byte-count into human KiB MiB etc; like du, ls1How to list ALL directories according to their size? [without including the parent directory]Unit multiplier conversion in a shell scriptList files, directories and executables in current directoryHow to display “human-readable” file sizes in find results?Listing directories based on size from largest to smallest on single lineHow do I set a file's mtime in epoch format?I accidentally GZIPed a whole bunch of files, one by one, instead of using tar(1). How can I undo this mess?How to zip only files under multiple subdirectories?How to tell the sizes of files and folders, sorted, and in MB, GB, instead of a long integer?List all directories whose contents (files) have not been updated or accessed before a certain date?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







-1















Few things to be achieved
1. Recursively get top 20 largest folders/files
2. Get their sizes in bytes as well as human readable format










share|improve this question







New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Possible duplicate of How do you sort du output by size?

    – Sparhawk
    1 hour ago


















-1















Few things to be achieved
1. Recursively get top 20 largest folders/files
2. Get their sizes in bytes as well as human readable format










share|improve this question







New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Possible duplicate of How do you sort du output by size?

    – Sparhawk
    1 hour ago














-1












-1








-1








Few things to be achieved
1. Recursively get top 20 largest folders/files
2. Get their sizes in bytes as well as human readable format










share|improve this question







New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Few things to be achieved
1. Recursively get top 20 largest folders/files
2. Get their sizes in bytes as well as human readable format







shell






share|improve this question







New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question







New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question






New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 1 hour ago









Rohan GhigeRohan Ghige

11




11




New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • Possible duplicate of How do you sort du output by size?

    – Sparhawk
    1 hour ago



















  • Possible duplicate of How do you sort du output by size?

    – Sparhawk
    1 hour ago

















Possible duplicate of How do you sort du output by size?

– Sparhawk
1 hour ago





Possible duplicate of How do you sort du output by size?

– Sparhawk
1 hour ago










1 Answer
1






active

oldest

votes


















0














#!/bin/bash
# ------------------------------------------
# Copy paste this content in a bash script e.g. ducks.sh
# And use it directly.
# ------------------------------------------
# Refer:
# https://www.cyberciti.biz/faq/linux-find-largest-file-in-directory-recursively-using-find-du/
# https://unix.stackexchange.com/a/220470/353485


function bytesToHR() {
local SIZE=$1
local UNITS="B KiB MiB GiB TiB PiB"
for F in $UNITS; do
local UNIT=$F
test ${SIZE%.*} -lt 1024 && break;
SIZE=$(echo "$SIZE / 1024" | bc -l)
done

if [ "$UNIT" == "B" ]; then
printf "%4.0f %sn" $SIZE $UNIT
else
printf "%7.02f %sn" $SIZE $UNIT
fi
}

du --block-size=1 --all ./ | sort -rn | head -n 20 > ./dump.txt
ALL_SIZES="`awk '{print $1}' ./dump.txt`"

# echo $ALL_SIZES

rm -f ./new_dump.txt

for s in $ALL_SIZES; do
bytesToHR $s >> ./new_dump.txt
done

paste ./new_dump.txt ./dump.txt





share|improve this answer








New contributor



Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Rohan Ghige is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f521660%2fuse-du-to-list-size-of-top-20-largest-folders-files-in-current-directory-recursi%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    #!/bin/bash
    # ------------------------------------------
    # Copy paste this content in a bash script e.g. ducks.sh
    # And use it directly.
    # ------------------------------------------
    # Refer:
    # https://www.cyberciti.biz/faq/linux-find-largest-file-in-directory-recursively-using-find-du/
    # https://unix.stackexchange.com/a/220470/353485


    function bytesToHR() {
    local SIZE=$1
    local UNITS="B KiB MiB GiB TiB PiB"
    for F in $UNITS; do
    local UNIT=$F
    test ${SIZE%.*} -lt 1024 && break;
    SIZE=$(echo "$SIZE / 1024" | bc -l)
    done

    if [ "$UNIT" == "B" ]; then
    printf "%4.0f %sn" $SIZE $UNIT
    else
    printf "%7.02f %sn" $SIZE $UNIT
    fi
    }

    du --block-size=1 --all ./ | sort -rn | head -n 20 > ./dump.txt
    ALL_SIZES="`awk '{print $1}' ./dump.txt`"

    # echo $ALL_SIZES

    rm -f ./new_dump.txt

    for s in $ALL_SIZES; do
    bytesToHR $s >> ./new_dump.txt
    done

    paste ./new_dump.txt ./dump.txt





    share|improve this answer








    New contributor



    Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0














      #!/bin/bash
      # ------------------------------------------
      # Copy paste this content in a bash script e.g. ducks.sh
      # And use it directly.
      # ------------------------------------------
      # Refer:
      # https://www.cyberciti.biz/faq/linux-find-largest-file-in-directory-recursively-using-find-du/
      # https://unix.stackexchange.com/a/220470/353485


      function bytesToHR() {
      local SIZE=$1
      local UNITS="B KiB MiB GiB TiB PiB"
      for F in $UNITS; do
      local UNIT=$F
      test ${SIZE%.*} -lt 1024 && break;
      SIZE=$(echo "$SIZE / 1024" | bc -l)
      done

      if [ "$UNIT" == "B" ]; then
      printf "%4.0f %sn" $SIZE $UNIT
      else
      printf "%7.02f %sn" $SIZE $UNIT
      fi
      }

      du --block-size=1 --all ./ | sort -rn | head -n 20 > ./dump.txt
      ALL_SIZES="`awk '{print $1}' ./dump.txt`"

      # echo $ALL_SIZES

      rm -f ./new_dump.txt

      for s in $ALL_SIZES; do
      bytesToHR $s >> ./new_dump.txt
      done

      paste ./new_dump.txt ./dump.txt





      share|improve this answer








      New contributor



      Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        0












        0








        0







        #!/bin/bash
        # ------------------------------------------
        # Copy paste this content in a bash script e.g. ducks.sh
        # And use it directly.
        # ------------------------------------------
        # Refer:
        # https://www.cyberciti.biz/faq/linux-find-largest-file-in-directory-recursively-using-find-du/
        # https://unix.stackexchange.com/a/220470/353485


        function bytesToHR() {
        local SIZE=$1
        local UNITS="B KiB MiB GiB TiB PiB"
        for F in $UNITS; do
        local UNIT=$F
        test ${SIZE%.*} -lt 1024 && break;
        SIZE=$(echo "$SIZE / 1024" | bc -l)
        done

        if [ "$UNIT" == "B" ]; then
        printf "%4.0f %sn" $SIZE $UNIT
        else
        printf "%7.02f %sn" $SIZE $UNIT
        fi
        }

        du --block-size=1 --all ./ | sort -rn | head -n 20 > ./dump.txt
        ALL_SIZES="`awk '{print $1}' ./dump.txt`"

        # echo $ALL_SIZES

        rm -f ./new_dump.txt

        for s in $ALL_SIZES; do
        bytesToHR $s >> ./new_dump.txt
        done

        paste ./new_dump.txt ./dump.txt





        share|improve this answer








        New contributor



        Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        #!/bin/bash
        # ------------------------------------------
        # Copy paste this content in a bash script e.g. ducks.sh
        # And use it directly.
        # ------------------------------------------
        # Refer:
        # https://www.cyberciti.biz/faq/linux-find-largest-file-in-directory-recursively-using-find-du/
        # https://unix.stackexchange.com/a/220470/353485


        function bytesToHR() {
        local SIZE=$1
        local UNITS="B KiB MiB GiB TiB PiB"
        for F in $UNITS; do
        local UNIT=$F
        test ${SIZE%.*} -lt 1024 && break;
        SIZE=$(echo "$SIZE / 1024" | bc -l)
        done

        if [ "$UNIT" == "B" ]; then
        printf "%4.0f %sn" $SIZE $UNIT
        else
        printf "%7.02f %sn" $SIZE $UNIT
        fi
        }

        du --block-size=1 --all ./ | sort -rn | head -n 20 > ./dump.txt
        ALL_SIZES="`awk '{print $1}' ./dump.txt`"

        # echo $ALL_SIZES

        rm -f ./new_dump.txt

        for s in $ALL_SIZES; do
        bytesToHR $s >> ./new_dump.txt
        done

        paste ./new_dump.txt ./dump.txt






        share|improve this answer








        New contributor



        Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.








        share|improve this answer



        share|improve this answer






        New contributor



        Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.








        answered 1 hour ago









        Rohan GhigeRohan Ghige

        11




        11




        New contributor



        Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




        New contributor




        Rohan Ghige is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.
























            Rohan Ghige is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Rohan Ghige is a new contributor. Be nice, and check out our Code of Conduct.













            Rohan Ghige is a new contributor. Be nice, and check out our Code of Conduct.












            Rohan Ghige is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f521660%2fuse-du-to-list-size-of-top-20-largest-folders-files-in-current-directory-recursi%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...