The blog

Unix get full size of directory folder

This issue has plagued me for awhile, but I never figured out the command to actually have unix print out the size of an entire directory. I came across the need handfuls of times over the years, but today I finally needed to actually learn this one.

So a bit of research led me to the following command:

steve$ ls
dir1  dir2  dir3
steve$ du -sh dir1
2.4M  dir1

Finally I can get the full file size of an entire directory via a shell. Hopefully I’ll remember that I posted this so message, for the next time I forget about this command.

By the way, about the arguments above: -s tells the shell I want size, and -h tells it I want it human readable.

11 Responses to “Unix get full size of directory folder”


  1. Dan Herman
    2008.11.13

    Actually the -s tells du you want to see entries for just the specified directories, rather than for all subdirectories. It’s equivalent to specifying a depth of zero (-d 0). See “man du”


  2. Steve
    2008.11.13

    Thanks for the correction, Dan. :)


  3. Hakiem
    2009.07.21

    Great tutorial. Very straight forward. I ve been looking for this for long time. Thanks!


  4. Roe Lee
    2009.07.23

    Simple tuts but useful. Thanks sir. :D


  5. Mayank Pandya
    2010.04.15

    That is a very helpful tip.

    Thanks!


  6. Andrew
    2010.05.12

    -h option only on Linux and not HP Unix.


  7. zslee
    2010.05.31

    thanks, simple and usefull


  8. Maram
    2011.08.15

    well …. I think its du -sk dir1 not du -sh.. coz I test


    • Steve Jamesson
      2011.08.15

      Run

      man du
      to see all the available options. The
      -k
      will display block counts while
      -h
      shows the file size in human readable. Most people would still want to use
      du -sh


  9. Seshu
    2011.09.20

    du =-s using this function we can get folder size as well as subfolders size


  10. seshu
    2011.09.20

    du -sk return the result in KB du -sh return the result in MB

Leave a Reply