Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I get the size of a directory on the command line?

I tried to obtain the size of a directory (containing directories and subdirectories) by using the ls command with option l. It seems to work for files (ls -l file name), but if I try to get the size of a directory (for instance, ls -l /home), I get only 4096 bytes, although altogether it is much bigger.
by

3 Answers

rahul07
The du command shows the disk usage of the file.

The -h option shows results in human-readable form (e.g., 4k, 5M, 3G).

du -h (file name)
rahul07
The du command shows the disk usage of the file.

The -h option shows results in human-readable form (e.g., 4k, 5M, 3G).

du -h (file name)
sandhya6gczb
For the total size of a directory jump into it and run:

du -hs



du -h --max-depth=1 | sort -hr

which will give you the size of all sub-folders (level 1). The output will be sorted (largest folder on top).

Login / Signup to Answer the Question.