Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List all packages installed using Homebrew and their sizes
brew list -f1 | 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

This comment has been minimized.

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

This comment has been minimized.

Copy link

akishaha commented Feb 23, 2019

Thanks, it worked for me too.

@simonkeng

This comment has been minimized.

Copy link

simonkeng commented Feb 25, 2019

Me too, thank you!

@Coldsp33d

This comment has been minimized.

Copy link

Coldsp33d commented Jun 8, 2019

This is really slow, is there something faster?

@evictor

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

NikhilVerma commented Nov 5, 2019

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

This comment has been minimized.

Copy link
Owner 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

This comment has been minimized.

Copy link

attriroot commented Nov 23, 2019

thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.