Useful snippets reference while using Homebrew the unofficial macos package manager.

Backup and Restore

# backup
# this command creates Brewfile which contains all your
# currently installed packages.
brew bundle dump

# restore
# in the directory containing Brewfile
brew bundle

Uninstall everything

brew remove --force $(brew list) --ignore-dependencies

List Installed packages

creates a Brewfile with all packages and taps

brew bundle dump

list all installed packages

brew list

list only top level packages

brew leaves

Cleanup

# remove old installation files
brew cleanup

# remove cache of currently installed packages
brew cleanup -s

# remove files older than $x days
brew cleanup --prune $x