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:
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:
Text-based:
They may not work exactly as you specified, but they should do most of what you need.
My variation on Brent's answer is:
Which will give you the largest directories or files in the tree.
You could do some similar using find:
But this won't be sorted by size and will be incredible slow and inefficient. Better off writing a script that parses du -a.
(Wanted to add this as a comment to Brent's answer but dont see a link to do that) I recently had a similar problem, and if you need to just check one partition in question, adding a -x to Brent's answer is pretty useful, especially if some directories have their own partition.
So it would be:
This gets you the sorted human-readable size of the top 10 largest files/folders in the entire directory tree:
Example
I'd have a short look into the manpage of sort - on some systems you can use
sort -h
to sort human-readable output. I've used this on CentOS 6.2 with sort 8.4. Otherwise you can redirect the output ofdu -h
to a file and sort that with something like:I don't know of a command-line tool that does this (other than what the other answers have suggested), but if you are able to run GUI programs on this machine, try KDirStat. It shows the disk usage of all files and directories under a particular root, sorted by size (by default).