How do I find the size of a directory on a Unix-like command-line?

20

4

I know this is a very basic question, but I searched the web and did not find a simple answer. I'm sure it's some kind of two or three letter command, right?

Langel

Posted 2012-03-10T18:29:56.483

Reputation: 303

Answers

43

du -s directory, as in "disk usage, sum"

Use du -sk to show the size in kilobytes (default is to show number of 512-byte blocks), or du -sh for a more human-friendly output. For more options, type man du.

Arne Stenström

Posted 2012-03-10T18:29:56.483

Reputation: 1 620

Actually I wanted 'du -s -b' so the size is in bytes. I don't know why the default is kilobytes without a 'kb' but it wasn't a convincing answer! ;D – Langel – 2012-03-10T19:02:19.593

6You can use -h flag for 'human readable', this makes automatic conversion in KB, MB, ect. – Ramzi Kahil – 2012-03-10T19:14:59.063

@Martin this is my favorite flag as well. – David – 2012-03-11T00:37:11.687

0

This is the same as -s, but replace 0 with 1 and you can get just the content in the folder:

du -h -d 0 /path/to/file

If you want the whole volume, you should use df instead of du (path is optional):

df -H /

Off-topic: One (very) spooky thing: I happend to be just a street away from Arne Stenström.

/Robert

Robert Jansson

Posted 2012-03-10T18:29:56.483

Reputation: 1