Skip to content

Instantly share code, notes, and snippets.

@eguven
Last active February 7, 2024 06:16
Show Gist options
  • Save eguven/23d8c9fc78856bd20f65f8bcf03e691b to your computer and use it in GitHub Desktop.
Save eguven/23d8c9fc78856bd20f65f8bcf03e691b to your computer and use it in GitHub Desktop.
List all packages installed using Homebrew and their sizes
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
@affanfarid
Copy link

affanfarid commented Sep 20, 2018

thanks, this helped, if you could format it to a table that would make it a lot better

@akishaha
Copy link

Thanks, it worked for me too.

@simonkeng
Copy link

Me too, thank you!

@Coldsp33d
Copy link

This is really slow, is there something faster?

@evictor
Copy link

evictor commented Jun 14, 2019

@Coldsp33d here's how to do it in parallel; note that you need parallel which you can install with brew install parallel. (Sorry, I couldn't figure out how to do this with xargs. 😬 )

brew list -f1 | parallel "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'"

@evictor
Copy link

evictor commented Jun 14, 2019

Can also do this to sort by size descending, though you won't see intermediate output while parallel goes:

brew list -f1 | parallel "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | sort -h -r

@NikhilVerma
Copy link

Just a small update, the sorting command is not correct at least for me

brew list -f1 | parallel "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | sort -k2 -hr

Sorts correctly because we are sorting the second column

@eguven
Copy link
Author

eguven commented Nov 5, 2019

I didn't want to require parallel dependency so I've updated the snippet to use xargs, added the sort and table output. Thanks for the suggestions everyone.

@attriroot
Copy link

thank you so much!

@jagdishadusumalli
Copy link

Just a small update, the sorting command is not correct at least for me

brew list -f1 | parallel "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | sort -k2 -hr

Sorts correctly because we are sorting the second column

Hi @NikhilVerma i tried your command and even others above but its failing for me
Error: ambiguous option: -f1

Am on macOS catalina 10.15.6 with CLT 11.5.0.0.1.1588476445.

Pls help out

@vasudev-hv
Copy link

Hi @NikhilVerma i tried your command and even others above but its failing for me
Error: ambiguous option: -f1

Am on macOS catalina 10.15.6 with CLT 11.5.0.0.1.1588476445.

Pls help out

@jagdishadusumalli Remove -f1 after brew list.

@jagdishadusumalli
Copy link

Hi @NikhilVerma i tried your command and even others above but its failing for me
Error: ambiguous option: -f1
Am on macOS catalina 10.15.6 with CLT 11.5.0.0.1.1588476445.
Pls help out

@jagdishadusumalli Remove -f1 after brew list.

Thanks Vasudev

@eguven
Copy link
Author

eguven commented Sep 18, 2020

I've removed -f1 from the gist, thanks @vasudev-hv and @jagdishadusumalli

@eguven
Copy link
Author

eguven commented Oct 29, 2020

Warning: Calling brew list to only list formulae is deprecated! Use brew list --formula instead.

Added --formula

@bkeys818
Copy link

bkeys818 commented Nov 1, 2020

Just an updated version for simpletons like me

brew install parallel; parallel --citation   #Skip this step if parallel is already installed
brew list --formula | parallel "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/{} \1/'" | sort -k2 -hr

@georgio
Copy link

georgio commented Feb 18, 2021

This is identical to what @bkeys818 posted except it's compatible with the fish shell

brew install parallel; parallel --citation   #Skip this step if parallel is already installed
brew list --formula | parallel "brew info {} | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*(/{}) \1/'" | sort -k2 -hr

@vogler
Copy link

vogler commented Nov 7, 2023

Alternative: brew install ncdu && ncdu /opt/homebrew/Cellar

@manan-gup
Copy link

Works on fish shell without parallel:

brew list --formula | xargs -P8 -I {} sh -c "brew info {} | grep -E '\([0-9]+ files'" \
| awk -F '[/(),]' '{print $6 ", " $8 ", " $9}' | sort -t "," -rh -k3

and gives output in a comma-separated format which can be simply changed in the awk command:

exiftool, 603 files,  25.3MB
micro, 7 files,  11.4MB
tealdeer, 12 files,  5.4MB
bat, 14 files,  4.6MB
eza, 14 files,  1.1MB

@adk-anw
Copy link

adk-anw commented Jan 15, 2024

Worked for me too! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment