Let's say I want to get the size of each directory of a Linux file system. When I use ls -la
I don't really get the summarized size of the folders.
If I use df
I get the size of each mounted file system but that also doesn't help me. And with du
I get the size of each subdirectory and the summary of the whole file system.
But I want to have only the summarized size of each directory within the ROOT folder of the file system. Is there any command to achieve that?
Best Answer
This does what you're looking for:
What this means:
-s
to give only the total for each command line argument.-h
for human-readable suffixes likeM
for megabytes andG
for gigabytes (optional)./*
simply expands to all directories (and files) in/
.Note: dotfiles are not included; run
shopt -s dotglob
to include those too.Also useful is sorting by size:
Here:
-h
ensures thatsort
interprets the human-readable suffixes correctly.