Find largest directories/files recursively [duplicate]
I'm looking for a script/program which will display the top x largest directories/files and then descend into those folders and display the x largest directories/files for a configurable depth.
231MB bin
- 220MB ls
- 190MB dir
- 15MB def
- 3MB lpr
- 10MB asd
- 1MB link
How can I do that?
You can see the 10 largest directories with:
du -cks *|sort -rn|head
This will recursively add up the sizes of everything in each directory - but you would have to manually execute it at each level to get a breakdown of what's in each
Chances are your system has one of these installed or available through your package manager:
Graphical:
- Baobab - aka Disk Usage Analyzer - Gnome (Applications>Accessories or Applications>System Tools)
- KDirStat - KDE
- Filelight - KDE
- TreeSize for Unix - GTK2
Text-based:
- ncdu - ncurses
- gt5 - text browser (lynx, w3m, etc. - auto-selected) - It's actually a shell script!
They may not work exactly as you specified, but they should do most of what you need.
My variation on Brent's answer is:
# du -a | sort -rn | head
Which will give you the largest directories or files in the tree.