Unix get full size of directory folder
June 18th, 2008
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
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.
November 13th, 2008 at 10:33 am
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”
November 13th, 2008 at 10:33 am
Thanks for the correction, Dan.