A utility for finding the largest directories and/or files in a given directory hierarchy. Biggest supports pretty printed and colorized output to the terminal:
All pretty printing and ANSI color codes are printed to STDERR, while the actual file paths are printed to STDOUT. Therefore, suppressing STDERR output will only print the file paths with no ANSI escape sequences, pretty printing, or file sizes, which can be used for scripting:
$ pip3 install biggest
Unlike similar utilities, Biggest will only return a directory if the sum of the sizes of its immediate files minus the sizes of any files included in the Biggest output make it large enough to be included. That’s a complicated, self-referential definition, so here’s an example:
- Say the directory
/tmp/looks like this:
/tmp/ ├── [25 MB] a.zip ├── [15 MB] b.zip └── /tmp/foo ├── [20 MB] c.zip └── [10 MB] d.zip
biggest /tmp/ -n 3will yield
b.zip. The directory
/tmp/foodid not make the cut because its file
b.zipwas large enough to be included, and therefore its 20 megabytes were not included in the size of
- Now lets say a new file
e.zipthat is 50 megabytes is added to
biggest /tmp/ -n 3will return
/tmp/foowas included this time because none of its files were large enough to make the cut, and therefore its size was interpreted as 30 megabytes.
Why does Biggest use this algorithm? Since a directory is always at least as large as its largest file, then, if Biggest didn’t use this algorithm, it would always return the directories containing the largest files!
Biggest uses a very efficient (and perhaps optimal) implementation of this algorithm. The worst case runtime is roughly O(𝑛 log 𝑚), where 𝑛 is the
-n argument passed to Biggest and 𝑚 is the number of files and directories being analyzed, but validating that is left as an exercise for the reader.
-fignore directories and only find the largest files
-hprints file sizes with human-readable unit suffixes like "MB" and "GB"
- Python 3.6 or newer