DU: how to view the 10 directories that take up the most space

Already once in DesdeLinux I showed them algunos commands that help us to see how we have occupied each MB on our hard drive, and among them I talked about du, a tool that has a lot of options, and that, with the help of some parameters, becomes more powerful.

According to Wikipedia:

du (Abbreviation of disk usage, disk usage) is a standard command for Unix family operating systems. It is used to estimate the hard disk space usage of a file, a particular directory, or files in a file system. Utility du first appeared in version 1 of AT&T Unix.

How to use it

DU

If we want to specifically see the weight of a file or folder in the easiest and most humane way possible, we execute:

$ du -bsh Videos/

What will return to us:

Related article:
DU: how to view the 10 directories that take up the most space
du -bsh Videos / 215G Videos /

Now, let's see which are the heaviest directories that we have in our / home organized from highest to lowest:

$ du -sm *

What it returns to us:

$ du -sm * 1172 Downloads 68855 Documents 4084 Desktop 22270 Images 174192 Linux 50887 Music 3088 Projects 1379 Work 219515 Videos

If we only wanted to see which are, for example, the 5 heaviest directories in our / home, we could use du with a series of extra commands, for example:

$ du -sm * | sort -nr | head -5

Which would return:

$ du -sm * | sort -nr | head -5 219515 Videos 174192 Linux 68855 Documents 50887 Music 22270 Images

But the values ​​they return to us are not "so human" as they are represented in MB and are more cumbersome to understand. That is why we run:

$ du -hs * | sort -nr | head -5

Which returns us:

$ du -hs * | sort -nr | head -5 215G Videos 171G Linux 68G Documents 50G Music 28K mageia-2013.svg

As you can see, contrary to what many people think, using the terminal is sometimes faster and more efficient than running a graphical application. Do you know of any other interesting combination for du?


29 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   eliotime3000 said

    SHUT UP AND TAKE MY ENTER !!!

    To tell the truth, every time I look for these kinds of utilities, it makes me want to ditch the graphical interface and live at the end of the console (well, I'm already doing it in OpenBSD, but something is something).

    In any case, with a console like Windows, I would dare to live without KDE or XFCE.

    1.    eliotime3000 said

      Errata. I meant Linux instead of Linux.

  2.   eliotime3000 said

    Errata. I meant Linux instead of Windows.

    1.    elav said

      eliotime3000 by god !!! We understood you man 😀

      1.    eliotime3000 said

        The problem is that when it comes to commenting from Android, either I don't have space to see everything I write, so it turns out to be uncomfortable to write (I prefer my netbook before using my cell phone to write a comment).

        1.    rawBasic said

          Then comment when you sit in front of the computer .. ..we wait for you calmly .. there is no rush .. 😛

          1.    eliotime3000 said

            Thanks for the advice. It is that I can not avoid commenting from my cell phone as soon as the RSS reader notifies me of a new blog entry that is published.

        2.    synflag said

          Eliotime, opera doesn't get along very well in my case with desde linux. Fast, light and usable than those I tested, surpassing uc browser because it supports flash and YouTube videos in iframes and next browser. It's not heavy at all and works very well.

          1.    synflag said

            Erratum. Hahahaha apparently it identifies as safari with iOS I assume because it is a tablet

  3.   Outdated said

    For those who like graphical interfaces more, I recommend the program called Filelight that you can find in the repositories of the vast majority of distros.

    http://en.wikipedia.org/wiki/Filelight

  4.   Otto Dietrich said

    Gnome's "Disk Usage Analyzer (Baobab)" is also an excellent choice. http://blogs.gnome.org/pbor/files/2012/09/Screenshot-from-2012-09-02-002755.png

  5.   FIXOCONN said

    du -s –yes *

  6.   river said

    yes but you have the command du -hs * | sort -nr | head -5 I find myself with the problem that it orders it numerically, not by weight, to sort them by weight you have to execute the command: du -hs * | sort -hr | head -5, I hope it could have served someone ^^

    1.    Anonymous said

      He served me, thank you

  7.   said

    sudo du -sxm / [^ p] * | sort -nr | head -n 15
    du -sm *. [^.] * | sort -nr | head -n 15

  8.   ripper_ said

    It is a good command but adding the -n option to sort will not correctly recognize the "human" numerical value and will show an 8,0K file as larger than a 7,9G file.

    You must use the -h option to sort so that this does not happen.

    PS: If you look at your example, the 5th heaviest file should have been Images and not mageia-2013.svg which only weighs 28K.

  9.   xykyz said

    The problem with using 'du -hs *' is that they don't sort well by size. For example:
    4'0K would appear before 3'5G
    800K would appear before 50G

    1.    eco-slacker said

      If the same thing happens to me:

      $ du -hs * | sort -nr | head -5
      577M torrents
      549M Documents
      288K sketchbook
      200K Downloads
      124M Podcast

      While the real thing, because I know my system very well, is:

      $ du -hsm * | sort -nr | head -5
      86008 Videos
      27328 Music
      17947 Work
      15108 Images
      1672 Dropbox

      ... you have piqued my curiosity, I am going to investigate a little more about this interesting combination of commands.

      Regards!

      1.    eco-slacker said

        Oh my God! the correct thing is "about" not with "h", sorry.

      2.    eco-slacker said

        Oh my God! the correct thing is "about" without "h", sorry.

      3.    vidagnu said

        Hello the command should be like this

        du-sh * | sort -rh | head -n 5

        In this way it will order them by weight.

        regards

  10.   msx said

    Check cdu: http://arsunik.free.fr/prog/cdu.html
    $ cdu -idh -s

  11.   alexander said

    Good afternoon, reading this article I remembered that there is a tool that generates a .png or .jpg image from the folders that one selects, for example, / home, to place it as a wallpaper, it is a very geek wallpaper, I don't know if anyone knows why I don't remember his name. Thanks

  12.   alexander said

    Why do I post comments and they don't appear?

    1.    msx said

      Do you press "Send to / dev / null" instead of "Post comment"?

  13.   Fernando Sancho Gonzalez-Calero said

    just a correction. In the last example where you use "du -sh" the sort must be done with "sort -hr" because "human" values ​​must be sorted with "human" sort. Sort is able to distinguish that 900K is less than 1MB, but if you limit yourself to the numerical ordering you won't notice.

  14.   Eider Chavez said

    Simply GREAT! Thank you for taking the time to publish this valuable post.
    …A hug for you.

  15.   Enrique said

    Hi all !!!
    Fantastic all the contributions (even the lapses of guindou instead of Linux, heh) in this thread as in all of the forum! Now a small reflection: reading comments I see that it is true when they say in those parts that Linux users are not normal eh? hahaha Hugs !!! And free greetings to all!

  16.   Miguel Angel said

    Very very good; clean and simple. Thank you.