Skip to content

Add a way to view the size of each installed formula/cask #20249

@simonomi

Description

@simonomi

Verification

Provide a detailed description of the proposed feature

Currently, the only way to view the amount of space a given installed formula or cask takes up is through the brew info command. This is fine, except that it doesn't scale to viewing the sizes for all installed formulas/casks. Since the size is inside a larger block of output, it's hard to parse it out at a glance, and even harder to compare multiple formulae/casks at once.

The specific way to add this functionality is open to suggestion. A new command like brew info --sizes that formats, sorts, and outputs the data would be best from a user-experience perspective (including a way to filter for leaf installs). Adding a new field to the json output of brew info would be also be great, if requiring more work to parse. A new option for brew info <formula|cask> that only prints the storage usage wouldn't be ideal, but it would still be a big improvement from the status quo.

What is the motivation for the feature?

If a user wants to clear up space on their device, removing large Homebrew installs is one way to do so. In order to know which formulae and casks are taking up the most space, users need a way to see the sizes of each one installed.

How will the feature be relevant to at least 90% of Homebrew users?

Everyone needs to clear up disk space from time to time. While macOS provides a screen in system settings for storage usage, it groups all formulae installed through Homebrew into one category. This means that users are unaware which formulae/casks are taking up the most space, and are unable to remove the ones taking up too much storage.

What alternatives to the feature have been considered?

The first result for "homebrew formula sizes" is a Stack Overflow question that suggests the following solution:

brew list --formula | xargs -n1 -P8 -I {} \
    sh -c "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | \
    sort -h -r -k2 - | column -t

Not only does this take a very long time to execute (nearly a full minute on my machine!), it's prone to breakage if the formatting of brew info ever changes. (Plus, it doesn't include casks. If you want it to include casks, removing --formula isn't enough—you have to modify the regex too!)

One could manually check the sizes of folders in brew --cellar and brew --caskroom, but poking around Homebrew's files manually isn't ideal, and that doesn't work for many casks because they frequently use symlinks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions