Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I would like to find the size of my installed brew packages so I can see how much space each is taking up. How do I go about doing this from the terminal?
Note:
some of the answers below also include brew cask packages which is also very helpful to this answer.
riffing off of PTao's solution, here's an ugly improved version which will include a human-readable sum of the combined sized of all package versions
for pkg in `brew list --formula -1 | egrep -v '\.|\.\.'`
do echo $pkg `brew info $pkg | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/\1/' | awk '{print $1;}/[0-9]$/{s+=$1};/[mM][bB]$/{s+=$1*(1024*1024);next};/[kK][bB]$/{s+=$1*1024;next} END { suffix=" KMGT"; for(i=1; s>1024 && i < length(suffix); i++) s/=1024; printf "\t(all versions: %0.1f%s)",s,substr(suffix, i, 1), $3; }'`
done
example output:
ack 173.5KB 178.4KB 182.7KB 190.5KB (all versions: 725.1K)
afl-fuzz 556.5KB 561.3KB (all versions: 1.1M)
aircrack-ng 934.2KB 953KB (all versions: 1.8M)
autoconf 1.9MB (all versions: 1.9M)
autojump 325.4KB (all versions: 325.4K)
automake 2.9MB 3.0MB 3MB (all versions: 8.9M)
bash-completion 608.6KB (all versions: 608.6K)
boost 414.6MB 398.7MB (all versions: 813.3M)
cairo 5.9MB 5.9MB (all versions: 11.8M)
cask 166.6KB (all versions: 166.6K)
cmake 31.4MB (all versions: 31.4M)
coreutils 8.5MB 7.9MB 9MB (all versions: 25.4M)
curl 3MB (all versions: 3.0M)
dos2unix 344.4KB 360.5KB (all versions: 704.9K)
ebook-tools 69.6KB 70.5KB (all versions: 140.1K)
eigen 3.5MB 6.5MB (all versions: 10.0M)
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
It display brews like below in sorted form (by size):
It's not exceedingly pretty, but you can do
$ brew list --formula | xargs brew info
And it will output something along the lines of
...
/usr/local/Cellar/ant/1.9.6 (1,611 files, 34.8M)
Poured from bottle on 2016-03-31 at 09:35:41
/usr/local/Cellar/ant/1.9.7 (1,611 files, 34.9M) *
Poured from bottle on 2016-12-15 at 09:58:56
..
for each package you have installed. I'm sure some wizard with grep could make this give you a nice table if you have many taps installed.
Colored list of all brew packages with size (and overall size of all versions)
for pkg in `brew list -f1 | egrep -v '\.|\.\.'`
do echo $pkg `brew info $pkg | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/\1/' | awk '{print "\033[1;32m"$1;}/[0-9]$/{s+=$1};/[mM][bB]$/{s+=$1*(1024*1024);next};/[kK][bB]$/{s+=$1*1024;next} END { suffix=" KBMBGBTB"; for(i=1; s>1024 && i < length(suffix); i+=2) s/=1024; printf "\033[0m\t(all versions: \033[33m%0.1f %s\033[0m)",s,substr(suffix, i, 2), $3; }'`
done
Output looks like this:
This shell snippet from https://gist.github.com/eguven/23d8c9fc78856bd20f65f8bcf03e691b will help you
for pkg in `brew list -f1 | egrep -v '\.|\.\.'`
do echo $pkg `brew info $pkg | egrep '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/\1/'`
done
On version Homebrew 2.7.5
Following command throw an error
brew list | xargs brew info | egrep --color '\d*\.\d*(KB|MB|GB)'
Error: Calling brew list to only list formulae is disabled! Use brew list --formula instead.
After adding --formula to brew list command it worked.
brew list --formula | xargs brew info | egrep --color '\d*\.\d*(KB|MB|GB)'
Related
I'm trying to create a code which will fetch the latest version of anaconda and install it.
Currently we can do this to install the latest version:
mkdir tmp
cd tmp
wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh
bash Anaconda3-2020.11-Linux-x86_64.sh
I want the script to be more generalized such that the code would automatically find the latest version of anaconda, download the shell script file and install it.
You can use this to get the latest version:
wget https://repo.anaconda.com/archive/ -q -O- |\
grep 'Anaconda3'| \
sed -n 's|.*>Anaconda3-\([0-9]\{4\}\.[0-9]\{2\}\)-.*|\1|p'
uniq |\
sort -r |\
head -1
This solution works only for those versions that use the year format (e.g. 2020-07), but since the latest version will presumably be of that format that should be fine.
Some explanation:
wget to fetch the contents of the archive page, which gives us the HTML content containing all the download URLs. -q quiets the output, -O- prints to stdout. Alternatively, you can use curl -s to the same effect.
grep 'Anaconda3' gives us the lines containing Anaconda, which contain the download links.
Use sed to select the version strings from the download links, e.g. 2020-11. That gives you a list of all versions (of the format YYYY-MM).
Sort that lists and select the first entry, which is the latest version.
Use the version in the rest of your script and you are done. A complete solution would be:
version=$(wget https://repo.anaconda.com/archive/ -q -O- |\
grep 'Anaconda3'|\
sed -n 's|.*>Anaconda3-\([0-9]\{4\}\.[0-9]\{2\}\)-.*|\1|p' |\
uniq |\
sort -r |\
head -1)
wget "https://repo.anaconda.com/archive/Anaconda3-$version-Linux-x86_64.sh"
I'm sure fetching the latest version could be made more efficient, but this should be sufficient for your use case.
I want to check if updates are available, and if so, perform some steps before I install the updates. I run yum check-updates to see a list of updates available for installed packages, but I'd like to grep this and get a count that I can use for some logic in a bash script. So ideally, I would like to grep that output of check-updates and return 0 if there are no updates, or if five updates are available then I would like the grep to return 5.
How can I grep this to return the count?
I like a simpler approach.
"yum -q" reduces the output from yum so it only displays a list of packages. Combine this with "wc -l" to count the number of lines output.
So to get a count of packages requiring updates I would run
sudo yum -q check-update | wc -l
Are you aware of grep -c? I've just created some nonsense file, giving following result:
Prompt> grep "AA" test.txt
1A01 TCCTTGAAAG
TCAACAAGAA
TCGCAAA
TTTAAAGTCGT
GGCGGAATCAATAC
GATGGAATATGCGCC
If I use grep -c, this is the result:
Prompt> grep -c "AA" test.txt
6
In case this does not answer your question completely, please edit your question and add some more information, just to show what you are looking for.
Also, please be aware that adding | wc -l behind every UNIX command reads the amount of results of that command.
This combination of awk and grep gives the count of available updates for installed packages:
yum check-updates | awk 'p;/^$/{p=1}' | grep -c "\."
This was based on the info in How to get just a list of yum updates
The -q for quiet is great but you may also want to grep out any blank lines and also the trailing Loaded plugins message. This works nicely for an accurate count:
yum check-update -q|egrep -v "Loaded plugins: langpacks, product-id, subscription-manager|^$"|wc -l
This question already has answers here:
How to upgrade all Python packages with pip
(56 answers)
Closed 4 years ago.
I have a bash command to upgrade all pip packages that I installed.
The command is:
pip3 list --outdated | cut -d' ' -f1 | tail -n +3 | xargs pip3 install --upgrade
The problem is that if one of the packages fails to upgrade, it rolls back deleting the upgrades of the ones that were successful upgraded.
Is there a way to upgrade all outdated packages with a single command discarding the failures of some packages?
I slightly modified the command posted in the duplicate of link.
pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U --user
I'm aware of gem dependency as a means to investigate a dependency graph, but I'm looking for something a little more straightforward. I only want to list gems that aren't dependencies of other gems.
In Homebrew, you can accomplish something similar with brew leaves - this lists packages that aren't dependencies of other packages. I mention this in case it's helpful in understanding what I'm trying to accomplish.
I've made a small shell script for that:
#!/bin/sh
GEMS_FILE=`mktemp`
DEPENDENCIES_FILE=`mktemp`
gem list -l | sed 's/ (.*//' | sort > $GEMS_FILE
cat $GEMS_FILE | xargs -n1 gem dependency -l --pipe | sed 's/ --version.*//' | sort -u > $DEPENDENCIES_FILE
comm -23 $GEMS_FILE $DEPENDENCIES_FILE
rm -f $GEMS_FILE $DEPENDENCIES_FILE
Also in a Gist form: https://gist.github.com/astyagun/290b783045afffb8190a0c75ab76d0fa
Sounds like you're looking for the gem list command.
If you're looking for gem help you can just run gem --help.
Is there a way to isolate the list of new packages added to homebrew?
When I run brew upgrade it lists all the new packages,
and I want to open their homepage to see if I want to use them.
Something along the lines of
$ brew home $(brew list --new)
which iterates through all the new packages and opens their homepage...
So you can string a couple commands to do this:
List the outdated packages:
$ brew outdated
git (1.8.5.1, 1.9.0, 2.0.0 < 2.2.0)
brew home only wants the name, not the versions, so parse that out
$ brew outdated | awk '{print $1}'
git
Run brew home:
$ brew home `brew outdated | awk '{print $1}'`
OR
$ brew outdated | awk '{print $1}' | xargs brew home
Optional: My machine errors out LSOpenURLsWithRole() failed with error -1712 if I try to open more then 6 urls. Quick googling suggests that it's a timeout, which suggests that your machine and browser may time out after more or less urls.
$ for package in `brew outdated | awk '{print $1}'`; do brew home $package; done