How to get top immediate sub-folders of '/' folder consuming huge disk space in Linux
du -h --max-depth=1 / | sort -h -r
This will show each folder in /
including /
itself.
Mind that this could take a long time to scan through all the files.
If you require any specific sizes of the subfolders in a folder, specify the exact path of the folder instead of /
or just skip /
if you're already in that folder.
-h
options shows sizes in human friendly format--max-depth=1
instructs command to go only 1 directory deep inside/
sort -h -r
sorts results using human friendly sizes and-r
instructs command to show results in reverse order (from largest to smallest directories)
This command will list the 15 largest in order:
du -xhS | sort -h | tail -n15
We use the -x
flag to skip directories on separate file systems.
The -h
on the du
gives the output in human readable format, sort -h
can then arrange this in order.
The -S
on the du
command means the size of subdirectories is excluded.
You can change the number of the tail
to see less or more. Super handy command.
Two other open source command line tools, that display top disk space used, are:
ncdu : available in the repo of most Linux distributions.
Top Disk Usage (tdu) : A single static binary with no dependencies, written in Golang.