6

In Homebrew, to clean up outdated packages, we do brew cleanup, and currently I have about 9.5GB worth of old packages, pending for removal.

However, I really do not like to remove old python versions. Are there ways to clean up old homebrew packages except python? It would be a dream to have command like brew cleanup -k python python3 (-k for formula to keep).

Thanks

Here is a list of packages from brew cleanup -n

Would remove: /usr/local/Cellar/aria2/1.18.9 (21 files, 4M)
Would remove: /usr/local/Cellar/aria2/1.19.0 (21 files, 4M)
Would remove: /usr/local/Cellar/aria2/1.19.2 (21 files, 4M)
Would remove: /usr/local/Cellar/aria2/1.19.3 (21 files, 4M)
Would remove: /usr/local/Cellar/boost/1.57.0 (10,572 files, 414.7M)
Would remove: /usr/local/Cellar/boost/1.58.0 (10,718 files, 433.5M)
Would remove: /usr/local/Cellar/boost/1.59.0 (10,928 files, 426.5M)
Would remove: /usr/local/Cellar/boost/1.60.0 (11,139 files, 436M)
Would remove: /usr/local/Cellar/cairo/1.14.2 (116 files, 6.4M)
Would remove: /usr/local/Cellar/cairo/1.14.2_1 (111 files, 6.0M)
Would remove: /usr/local/Cellar/cairo/1.14.4 (112 files, 5.9M)
Would remove: /usr/local/Cellar/cairo/1.14.6 (112 files, 5.9M)
Would remove: /usr/local/Cellar/cloog/0.18.1 (33 files, 465K)
Would remove: /usr/local/Cellar/cloog/0.18.3 (33 files, 461K)
Would remove: /usr/local/Cellar/coreutils/8.23_1 (214 files, 9.2M)
Would remove: /usr/local/Cellar/coreutils/8.24 (214 files, 8.2M)
Would remove: /usr/local/Cellar/curl/7.41.0_1 (301 files, 2.4M)
Would remove: /usr/local/Cellar/curl/7.42.0 (304 files, 2.4M)
Would remove: /usr/local/Cellar/curl/7.42.1 (305 files, 2.4M)
Would remove: /usr/local/Cellar/curl/7.43.0 (307 files, 2.4M)
Would remove: /usr/local/Cellar/curl/7.44.0 (310 files, 2.4M)
Would remove: /usr/local/Cellar/curl/7.45.0 (355 files, 2.5M)
Would remove: /usr/local/Cellar/curl/7.46.0 (359 files, 2.5M)
Would remove: /usr/local/Cellar/curl/7.47.0 (359 files, 2.5M)
Would remove: /usr/local/Cellar/eigen/3.2.4 (361 files, 3.4M)
Would remove: /usr/local/Cellar/eigen/3.2.5 (367 files, 3.4M)
Would remove: /usr/local/Cellar/eigen/3.2.6 (367 files, 3.4M)
Would remove: /usr/local/Cellar/eigen/3.2.7 (368 files, 3.5M)
Would remove: /usr/local/Cellar/fontconfig/2.11.1 (448 files, 2.6M)
Would remove: /usr/local/Cellar/fontconfig/2.11.1_1 (449 files, 2.9M)
Would remove: /usr/local/Cellar/freetype/2.5.5 (60 files, 2.5M)
Would remove: /usr/local/Cellar/freetype/2.6 (60 files, 2.5M)
Would remove: /usr/local/Cellar/freetype/2.6.2 (60 files, 2.4M)
Would remove: /usr/local/Cellar/freetype/2.6_1 (60 files, 2.5M)
Would remove: /usr/local/Cellar/gcc/4.9.2_1 (1,156 files, 207.2M)
Would remove: /usr/local/Cellar/gcc/5.1.0 (1,351 files, 251.7M)
Would remove: /usr/local/Cellar/gcc/5.2.0 (1,353 files, 251.8M)
Would remove: /usr/local/Cellar/gettext/0.19.4 (1,920 files, 15.6M)
Would remove: /usr/local/Cellar/gettext/0.19.5.1 (1,921 files, 16.2M)
Would remove: /usr/local/Cellar/gettext/0.19.6 (1,921 files, 16.4M)
Would remove: /usr/local/Cellar/git/2.3.5 (1,363 files, 212.5M)
Would remove: /usr/local/Cellar/git/2.3.6 (1,364 files, 212.5M)
Would remove: /usr/local/Cellar/git/2.3.7 (1,365 files, 212.9M)
Would remove: /usr/local/Cellar/git/2.4.0 (1,368 files, 213M)
Would remove: /usr/local/Cellar/git/2.4.1 (1,370 files, 213.6M)
Would remove: /usr/local/Cellar/git/2.4.2 (1,371 files, 213.6M)
Would remove: /usr/local/Cellar/git/2.4.3 (1,372 files, 214.1M)
Would remove: /usr/local/Cellar/git/2.4.4 (1,373 files, 214.1M)
Would remove: /usr/local/Cellar/git/2.4.5 (1,375 files, 214.1M)
Would remove: /usr/local/Cellar/git/2.4.6 (1,376 files, 214.2M)
Would remove: /usr/local/Cellar/git/2.5.0 (1,383 files, 220.9M)
Would remove: /usr/local/Cellar/git/2.5.1 (1,385 files, 220.9M)
Would remove: /usr/local/Cellar/git/2.6.2 (1,398 files, 232.3M)
Would remove: /usr/local/Cellar/git/2.6.3 (1,400 files, 232.9M)
Would remove: /usr/local/Cellar/git/2.6.4 (1,401 files, 232.9M)
Would remove: /usr/local/Cellar/git/2.7.0 (1,407 files, 235.8M)
Would remove: /usr/local/Cellar/git/2.7.1 (1,408 files, 236.3M)
Would remove: /usr/local/Cellar/glib/2.44.0 (416 files, 17.6M)
Would remove: /usr/local/Cellar/glib/2.44.1 (416 files, 16.8M)
Would remove: /usr/local/Cellar/glib/2.46.1 (416 files, 17.9M)
Would remove: /usr/local/Cellar/glib/2.46.1_1 (421 files, 22.3M)
Would remove: /usr/local/Cellar/gmp/6.0.0a (15 files, 3.2M)
Would remove: /usr/local/Cellar/gnupg2/2.0.27 (87 files, 3.7M)
Would remove: /usr/local/Cellar/gnupg2/2.0.28 (87 files, 3.7M)
Would remove: /usr/local/Cellar/gnutls/3.3.14 (1,020 files, 6.3M)
Would remove: /usr/local/Cellar/gnutls/3.3.15 (1,020 files, 6.3M)
Would remove: /usr/local/Cellar/gnutls/3.3.16 (1,020 files, 6.3M)
Would remove: /usr/local/Cellar/gnutls/3.3.17.1 (1,020 files, 6.3M)
Would remove: /usr/local/Cellar/gnutls/3.3.18 (1,020 files, 6.3M)
Would remove: /usr/local/Cellar/gnutls/3.3.20 (1,020 files, 6.3M)
Would remove: /usr/local/Cellar/gnutls/3.4.8 (1,094 files, 6.8M)
Would remove: /usr/local/Cellar/gpg-agent/2.0.27 (12 files, 686.7K)
Would remove: /usr/local/Cellar/gpg-agent/2.0.28 (11 files, 695.8K)
Would remove: /usr/local/Cellar/ilmbase/2.1.0 (75 files, 1.4M)
Would remove: /usr/local/Cellar/isl/0.12.2 (55 files, 3.0M)
Would remove: /usr/local/Cellar/isl/0.14.1 (68 files, 3.2M)
Would remove: /usr/local/Cellar/libassuan/2.2.0 (12 files, 304.3K)
Would remove: /usr/local/Cellar/libassuan/2.2.1 (12 files, 306K)
Would remove: /usr/local/Cellar/libassuan/2.3.0 (12 files, 310.6K)
Would remove: /usr/local/Cellar/libassuan/2.3.0_1 (13 files, 406.6K)
Would remove: /usr/local/Cellar/libassuan/2.4.0 (13 files, 418.6K)
Would remove: /usr/local/Cellar/libgcrypt/1.6.3 (16 files, 1.2M)
Would remove: /usr/local/Cellar/libgcrypt/1.6.3_1 (16 files, 1.2M)
Would remove: /usr/local/Cellar/libgcrypt/1.6.3_2 (16 files, 1.2M)
Would remove: /usr/local/Cellar/libgcrypt/1.6.4 (16 files, 1.2M)
Would remove: /usr/local/Cellar/libgcrypt/1.6.4_1 (16 files, 1.2M)
Would remove: /usr/local/Cellar/libgpg-error/1.19 (17 files, 308.6K)
Would remove: /usr/local/Cellar/libgpg-error/1.20 (17 files, 314.3K)
Would remove: /usr/local/Cellar/libgpg-error/1.20_1 (18 files, 404.8K)
Would remove: /usr/local/Cellar/libpng/1.6.17 (17 files, 1.2M)
Would remove: /usr/local/Cellar/libpng/1.6.18 (17 files, 1.2M)
Would remove: /usr/local/Cellar/libpng/1.6.19 (17 files, 1.2M)
Would remove: /usr/local/Cellar/libpng/1.6.20 (17 files, 1.2M)
Would remove: /usr/local/Cellar/libtasn1/4.4 (56 files, 441.2K)
Would remove: /usr/local/Cellar/libtasn1/4.5 (56 files, 441.6K)
Would remove: /usr/local/Cellar/libtiff/4.0.3 (254 files, 3.3M)
Would remove: /usr/local/Cellar/libtiff/4.0.4 (257 files, 3.5M)
Would remove: /usr/local/Cellar/libusb/1.0.19 (11 files, 332.8K)
Would remove: /usr/local/Cellar/macvim/7.4-74 (1,842 files, 23.9M)
Would remove: /usr/local/Cellar/macvim/7.4-75 (1,902 files, 29.7M)
Would remove: /usr/local/Cellar/macvim/7.4-76 (1,902 files, 29.7M)
Would remove: /usr/local/Cellar/macvim/7.4-77 (1,905 files, 29.7M)
Would remove: /usr/local/Cellar/macvim/7.4-79 (1,914 files, 30.0M)
Would remove: /usr/local/Cellar/macvim/7.4-80 (1,918 files, 30.0M)
Would remove: /usr/local/Cellar/macvim/7.4-81 (1,918 files, 30.0M)
Would remove: /usr/local/Cellar/macvim/7.4-83 (1,910 files, 30.0M)
Would remove: /usr/local/Cellar/macvim/7.4-84 (1,910 files, 30.0M)
Would remove: /usr/local/Cellar/macvim/7.4-85 (1,910 files, 30M)
Would remove: /usr/local/Cellar/macvim/7.4-86 (1,910 files, 30M)
Would remove: /usr/local/Cellar/macvim/7.4-87 (1,913 files, 30M)
Would remove: /usr/local/Cellar/macvim/7.4-88 (1,913 files, 30M)
Would remove: /usr/local/Cellar/macvim/7.4-89 (1,921 files, 30.8M)
Would remove: /usr/local/Cellar/macvim/7.4-95 (2,434 files, 37.3M)
Would remove: /usr/local/Cellar/macvim/7.4-96 (2,068 files, 32.6M)
Would remove: /usr/local/Cellar/mpfr/3.1.2-p11 (24 files, 3.4M)
Would remove: /usr/local/Cellar/nettle/2.7.1 (66 files, 1.6M)
Would remove: /usr/local/Cellar/nettle/3.1 (75 files, 1.9M)
Would remove: /usr/local/Cellar/node/0.12.2_1 (2,603 files, 20.8M)
Would remove: /usr/local/Cellar/node/0.12.4 (2,590 files, 20.9M)
Would remove: /usr/local/Cellar/node/0.12.5 (2,681 files, 21M)
Would remove: /usr/local/Cellar/node/0.12.6 (2,726 files, 21.9M)
Would remove: /usr/local/Cellar/node/0.12.7 (2,726 files, 23.4M)
Would remove: /usr/local/Cellar/node/4.2.1 (2,738 files, 28.6M)
Would remove: /usr/local/Cellar/node/5.0.0 (2,824 files, 28.6M)
Would remove: /usr/local/Cellar/node/5.1.0 (2,827 files, 28.6M)
Would remove: /usr/local/Cellar/node/5.1.1 (2,827 files, 28.6M)
Would remove: /usr/local/Cellar/node/5.3.0 (2,827 files, 29.4M)
Would remove: /usr/local/Cellar/node/5.4.0 (2,827 files, 34.2M)
Would remove: /usr/local/Cellar/node/5.4.1 (2,827 files, 34.2M)
Would remove: /usr/local/Cellar/node/5.4.1_1 (3,135 files, 35.5M)
Would remove: /usr/local/Cellar/node/5.5.0 (3,135 files, 35.5M)
Would remove: /usr/local/Cellar/node/5.6.0 (3,726 files, 35.3M)
Would remove: /usr/local/Cellar/numpy/1.10.1 (498 files, 9.1M)
Would remove: /usr/local/Cellar/numpy/1.9.2 (692 files, 12.2M)
Would remove: /usr/local/Cellar/numpy/1.9.2_1 (452 files, 8.5M)
Would remove: /usr/local/Cellar/opencv/2.4.11 (222 files, 35.1M)
Would remove: /usr/local/Cellar/opencv/2.4.11_1 (222 files, 35.0M)
Would remove: /usr/local/Cellar/opencv/2.4.11_2 (222 files, 35.0M)
Would remove: /usr/local/Cellar/opencv/2.4.12 (225 files, 35.8M)
Would remove: /usr/local/Cellar/openexr/2.1.0 (127 files, 7.6M)
Would remove: /usr/local/Cellar/openssl/1.0.2 (459 files, 12.1M)
Would remove: /usr/local/Cellar/openssl/1.0.2a-1 (463 files, 12.1M)
Would remove: /usr/local/Cellar/openssl/1.0.2c (463 files, 12.2M)
Would remove: /usr/local/Cellar/openssl/1.0.2d_1 (464 files, 12.2M)
Would remove: /usr/local/Cellar/openssl/1.0.2e (465 files, 11.9M)
Would remove: /usr/local/Cellar/openssl/1.0.2e_1 (465 files, 11.9M)
Would remove: /usr/local/Cellar/pcre/8.36 (146 files, 5.3M)
Would remove: /usr/local/Cellar/pcre/8.37 (146 files, 5.4M)
Would remove: /usr/local/Cellar/pinentry/0.9.1 (9 files, 125.7K)
Would remove: /usr/local/Cellar/pinentry/0.9.2 (9 files, 133.2K)
Would remove: /usr/local/Cellar/pinentry/0.9.3 (9 files, 154.0K)
Would remove: /usr/local/Cellar/pinentry/0.9.4 (9 files, 155K)
Would remove: /usr/local/Cellar/pinentry/0.9.5 (10 files, 205.5K)
Would remove: /usr/local/Cellar/pixman/0.32.6 (11 files, 1.4M)
Would remove: /usr/local/Cellar/pixman/0.32.8 (11 files, 1.2M)
Would remove: /usr/local/Cellar/pkg-config/0.28 (10 files, 580.3K)
Would remove: /usr/local/Cellar/python/2.7.10 (4,788 files, 67.3M)
Would remove: /usr/local/Cellar/python/2.7.10_1 (4,872 files, 65.3M)
Would remove: /usr/local/Cellar/python/2.7.10_2 (4,937 files, 66.3M)
Would remove: /usr/local/Cellar/python/2.7.9 (4,835 files, 68.6M)
Would remove: /usr/local/Cellar/python3/3.4.3 (4,655 files, 71.2M)
Would remove: /usr/local/Cellar/python3/3.4.3_1 (4,697 files, 68.2M)
Would remove: /usr/local/Cellar/python3/3.4.3_2 (4,697 files, 68.2M)
Would remove: /usr/local/Cellar/python3/3.5.0 (7,612 files, 105.8M)
Would remove: /usr/local/Cellar/r/3.2.0 (2,204 files, 51.1M)
Would remove: /usr/local/Cellar/r/3.2.0_1 (2,204 files, 51.1M)
Would remove: /usr/local/Cellar/r/3.2.1_1 (2,172 files, 53.8M)
Would remove: /usr/local/Cellar/r/3.2.2 (2,175 files, 54.0M)
Would remove: /usr/local/Cellar/r/3.2.2_1 (2,175 files, 53.9M)
Would remove: /usr/local/Cellar/sqlite/3.10.0 (9 files, 2.8M)
Would remove: /usr/local/Cellar/sqlite/3.10.2 (9 files, 2.8M)
Would remove: /usr/local/Cellar/sqlite/3.8.10.2 (9 files, 2.8M)
Would remove: /usr/local/Cellar/sqlite/3.8.11 (9 files, 2.8M)
Would remove: /usr/local/Cellar/sqlite/3.8.11.1 (9 files, 2.8M)
Would remove: /usr/local/Cellar/sqlite/3.8.9 (9 files, 2.1M)
Would remove: /usr/local/Cellar/sqlite/3.9.1 (9 files, 2.8M)
Would remove: /usr/local/Cellar/sqlite/3.9.2 (9 files, 2.8M)
Would remove: /usr/local/Cellar/sshuttle/0.61 (80 files, 549.2K)
Would remove: /usr/local/Cellar/sshuttle/0.71 (57 files, 462.3K)
Would remove: /usr/local/Cellar/sshuttle/0.72 (57 files, 492.6K)
Would remove: /usr/local/Cellar/sshuttle/0.73 (48 files, 301.7K)
Would remove: /usr/local/Cellar/tmux/1.9a (16 files, 597.8K)
Would remove: /usr/local/Cellar/tmux/2.0 (16 files, 619.2K)
Would remove: /usr/local/Cellar/vim/7.4.1016 (1,620 files, 24.9M)
Would remove: /usr/local/Cellar/vim/7.4.1063 (1,620 files, 24.6M)
Would remove: /usr/local/Cellar/vim/7.4.1090 (1,621 files, 24.7M)
Would remove: /usr/local/Cellar/vim/7.4.1190 (1,621 files, 24.7M)
Would remove: /usr/local/Cellar/vim/7.4.1257 (1,623 files, 24.8M)
Would remove: /usr/local/Cellar/vim/7.4.1301 (1,623 files, 24.8M)
Would remove: /usr/local/Cellar/vim/7.4.488 (1,600 files, 21.6M)
Would remove: /usr/local/Cellar/vim/7.4.712 (1,606 files, 21.8M)
Would remove: /usr/local/Cellar/vim/7.4.712_1 (1,606 files, 24.2M)
Would remove: /usr/local/Cellar/vim/7.4.826 (1,612 files, 24.3M)
Would remove: /usr/local/Cellar/vim/7.4.898 (1,612 files, 24.5M)
Would remove: /usr/local/Cellar/vim/7.4.903 (1,618 files, 24.5M)
Would remove: /usr/local/Cellar/vim/7.4.936 (1,620 files, 24.5M)
Would remove: /usr/local/Cellar/vim/7.4.944 (1,620 files, 24.5M)
Would remove: /usr/local/Cellar/vim/7.4.979 (1,620 files, 24.5M)
Would remove: /usr/local/Cellar/wget/1.16.3 (9 files, 1.5M)
Would remove: /usr/local/Cellar/wget/1.17 (9 files, 1.5M)
Would remove: /usr/local/Cellar/xz/5.2.1 (59 files, 1.4M)
Would remove: /usr/local/Cellar/youtube-dl/2015.04.17 (8 files, 998.9K)
Would remove: /usr/local/Cellar/youtube-dl/2015.04.28 (8 files, 1012.2K)
Would remove: /usr/local/Cellar/youtube-dl/2015.05.04 (8 files, 1016K)
Would remove: /usr/local/Cellar/youtube-dl/2015.05.20 (8 files, 1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.05.29 (8 files, 1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.06.04.1 (8 files, 1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.06.25 (8 files, 1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.07.04 (8 files, 1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.07.07 (9 files, 1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.07.21 (9 files, 1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.07.28 (9 files, 1.1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.08.06.1 (9 files, 1.1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.08.09 (9 files, 1.1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.08.16 (9 files, 1.1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.08.28 (9 files, 1.1M)
Would remove: /usr/local/Cellar/youtube-dl/2015.10.18 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2015.11.02 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2015.11.21 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2015.11.24 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2015.12.06 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2015.12.18 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2015.12.23 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2016.01.01 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2016.01.09 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2016.01.14 (9 files, 1.2M)
Would remove: /usr/local/Cellar/youtube-dl/2016.02.01 (9 files, 1.3M)
Would remove: /usr/local/Cellar/youtube-dl/2016.02.05.1 (9 files, 1.3M)
Would remove: /usr/local/Cellar/youtube-dl/2016.02.10 (9 files, 1.3M)
Would remove: /usr/local/Cellar/youtube-dl/2016.02.13 (9 files, 1.3M)
Would remove: /usr/local/Cellar/youtube-dl/2016.02.22 (9 files, 1.3M)
Would remove: /usr/local/Cellar/zsh/5.0.8 (1,113 files, 8.4M)
Would remove: /usr/local/Cellar/zsh/5.1.1 (1,127 files, 8.6M)
Would remove: /Library/Caches/Homebrew/aria2-1.19.2.el_capitan.bottle.tar.gz (1.2M)
Would remove: /Library/Caches/Homebrew/aria2-1.19.3.el_capitan.bottle.tar.gz (1.2M)
Would remove: /Library/Caches/Homebrew/boost-1.59.0.el_capitan.bottle.tar.gz (83.5M)
Would remove: /Library/Caches/Homebrew/boost-1.60.0.el_capitan.bottle.tar.gz (85M)
Would remove: /Library/Caches/Homebrew/cairo-1.14.4.el_capitan.bottle.tar.gz (1.6M)
Would remove: /Library/Caches/Homebrew/cairo-1.14.6.el_capitan.bottle.tar.gz (1.6M)
Would remove: /Library/Caches/Homebrew/curl-7.45.0.el_capitan.bottle.tar.gz (794.9K)
Would remove: /Library/Caches/Homebrew/curl-7.46.0.el_capitan.bottle.tar.gz (802.7K)
Would remove: /Library/Caches/Homebrew/curl-7.47.0.el_capitan.bottle.tar.gz (804.7K)
Would remove: /Library/Caches/Homebrew/eigen-3.2.6.el_capitan.bottle.tar.gz (684.9K)
Would remove: /Library/Caches/Homebrew/eigen-3.2.7.el_capitan.bottle.tar.gz (692K)
Would remove: /Library/Caches/Homebrew/fontconfig-2.11.1_1.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/freetype-2.6.2.el_capitan.bottle.tar.gz (816.0K)
Would remove: /Library/Caches/Homebrew/gettext-0.19.6.el_capitan.bottle.tar.gz (7.4M)
Would remove: /Library/Caches/Homebrew/git-2.6.2.el_capitan.bottle.tar.gz (10.9M)
Would remove: /Library/Caches/Homebrew/git-2.6.3.el_capitan.bottle.tar.gz (11.0M)
Would remove: /Library/Caches/Homebrew/git-2.6.4.el_capitan.bottle.tar.gz (11.0M)
Would remove: /Library/Caches/Homebrew/git-2.7.0.el_capitan.bottle.tar.gz (11M)
Would remove: /Library/Caches/Homebrew/git-2.7.1.el_capitan.bottle.tar.gz (11M)
Would remove: /Library/Caches/Homebrew/glib-2.46.1.el_capitan.bottle.tar.gz (5M)
Would remove: /Library/Caches/Homebrew/glib-2.46.1_1.el_capitan.bottle.tar.gz (6.5M)
Would remove: /Library/Caches/Homebrew/gnutls-3.3.18.el_capitan.bottle.tar.gz (1.8M)
Would remove: /Library/Caches/Homebrew/gnutls-3.3.20.el_capitan.bottle.tar.gz (1.8M)
Would remove: /Library/Caches/Homebrew/gnutls-3.4.8.el_capitan.bottle.tar.gz (1.9M)
Would remove: /Library/Caches/Homebrew/libassuan-2.3.0_1.el_capitan.bottle.tar.gz (135.2K)
Would remove: /Library/Caches/Homebrew/libassuan-2.4.0.el_capitan.bottle.tar.gz (139.6K)
Would remove: /Library/Caches/Homebrew/libgcrypt-1.6.4.el_capitan.bottle.tar.gz (473.9K)
Would remove: /Library/Caches/Homebrew/libgcrypt-1.6.4_1.el_capitan.bottle.tar.gz (474.0K)
Would remove: /Library/Caches/Homebrew/libgpg-error-1.20_1.el_capitan.bottle.tar.gz (126.8K)
Would remove: /Library/Caches/Homebrew/libpng-1.6.19.el_capitan.bottle.tar.gz (425.3K)
Would remove: /Library/Caches/Homebrew/libpng-1.6.20.el_capitan.bottle.tar.gz (425.8K)
Would remove: /Library/Caches/Homebrew/macvim-7.4-79.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-80.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-81.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-83.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-84.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-85.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-86.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-87.tar.gz (17.1M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-88.tar.gz (17M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-89.tar.gz (17.4M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-95.tar.gz (18.1M)
Would remove: /Library/Caches/Homebrew/macvim-7.4-96.tar.gz (18M)
Would remove: /Library/Caches/Homebrew/nettle-3.1.el_capitan.bottle.tar.gz (696.7K)
Would remove: /Library/Caches/Homebrew/node-4.2.1.el_capitan.bottle.tar.gz (8.7M)
Would remove: /Library/Caches/Homebrew/node-5.0.0.el_capitan.bottle.tar.gz (8.7M)
Would remove: /Library/Caches/Homebrew/node-5.1.0.el_capitan.bottle.tar.gz (8.7M)
Would remove: /Library/Caches/Homebrew/node-5.1.1.el_capitan.bottle.tar.gz (8.7M)
Would remove: /Library/Caches/Homebrew/node-5.3.0.el_capitan.bottle.tar.gz (8.9M)
Would remove: /Library/Caches/Homebrew/node-5.4.0.el_capitan.bottle.tar.gz (9.6M)
Would remove: /Library/Caches/Homebrew/node-5.4.1.el_capitan.bottle.tar.gz (9.6M)
Would remove: /Library/Caches/Homebrew/node-5.4.1_1.el_capitan.bottle.tar.gz (10M)
Would remove: /Library/Caches/Homebrew/node-5.5.0.el_capitan.bottle.tar.gz (10M)
Would remove: /Library/Caches/Homebrew/node-5.6.0.el_capitan.bottle.tar.gz (9.9M)
Would remove: /Library/Caches/Homebrew/numpy-1.10.1.el_capitan.bottle.tar.gz (2.2M)
Would remove: /Library/Caches/Homebrew/openssl-1.0.2e.el_capitan.bottle.tar.gz (3.6M)
Would remove: /Library/Caches/Homebrew/openssl-1.0.2e_1.el_capitan.bottle.tar.gz (3.6M)
Would remove: /Library/Caches/Homebrew/pdftotext-latest.dmg.incomplete (520K)
Would remove: /Library/Caches/Homebrew/pinentry-0.9.7.el_capitan.bottle.tar.gz (62.3K)
Would remove: /Library/Caches/Homebrew/pixman-0.32.8.el_capitan.bottle.tar.gz (453.1K)
Would remove: /Library/Caches/Homebrew/python-2.7.11.el_capitan.bottle.tar.gz (16.5M)
Would remove: /Library/Caches/Homebrew/python3-3.5.0.tar.xz (14.1M)
Would remove: /Library/Caches/Homebrew/python3-3.5.1.el_capitan.bottle.tar.gz (12.6M)
Would remove: /Library/Caches/Homebrew/r-3.2.3.el_capitan.bottle.tar.gz (36.9M)
Would remove: /Library/Caches/Homebrew/sqlite-3.10.0.el_capitan.bottle.tar.gz (1.3M)
Would remove: /Library/Caches/Homebrew/sqlite-3.10.2.el_capitan.bottle.tar.gz (1.3M)
Would remove: /Library/Caches/Homebrew/sqlite-3.9.1.el_capitan.bottle.1.tar.gz (1.3M)
Would remove: /Library/Caches/Homebrew/sqlite-3.9.2.el_capitan.bottle.tar.gz (1.3M)
Would remove: /Library/Caches/Homebrew/sshuttle-0.72.tar.gz (203K)
Would remove: /Library/Caches/Homebrew/sshuttle-0.73.tar.gz (52K)
Would remove: /Library/Caches/Homebrew/tmux-2.1.el_capitan.bottle.tar.gz (261.8K)
Would remove: /Library/Caches/Homebrew/vim-7.4.1016.tar.gz (12M)
Would remove: /Library/Caches/Homebrew/vim-7.4.1063.tar.gz (11.8M)
Would remove: /Library/Caches/Homebrew/vim-7.4.1090.tar.gz (12.0M)
Would remove: /Library/Caches/Homebrew/vim-7.4.1190.tar.gz (12M)
Would remove: /Library/Caches/Homebrew/vim-7.4.1257.tar.gz (12M)
Would remove: /Library/Caches/Homebrew/vim-7.4.1301.tar.gz (12M)
Would remove: /Library/Caches/Homebrew/vim-7.4.898.tar.gz (11.7M)
Would remove: /Library/Caches/Homebrew/vim-7.4.903.tar.gz (11.7M)
Would remove: /Library/Caches/Homebrew/vim-7.4.936.tar.gz (11.7M)
Would remove: /Library/Caches/Homebrew/vim-7.4.944.tar.gz (11.7M)
Would remove: /Library/Caches/Homebrew/vim-7.4.979.tar.gz (11.7M)
Would remove: /Library/Caches/Homebrew/wget-1.17.1.el_capitan.bottle.tar.gz (545.1K)
Would remove: /Library/Caches/Homebrew/wget-1.17.el_capitan.bottle.tar.gz (543.0K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2015.10.18.el_capitan.bottle.tar.gz (977.9K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2015.11.02.el_capitan.bottle.tar.gz (985.0K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2015.11.21.el_capitan.bottle.tar.gz (995.7K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2015.11.24.el_capitan.bottle.tar.gz (997.3K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2015.12.06.el_capitan.bottle.tar.gz (1005.9K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2015.12.18.el_capitan.bottle.tar.gz (1016.5K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2015.12.23.el_capitan.bottle.tar.gz (1022.5K)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.01.01.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.01.09.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.01.14.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.02.01.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.02.05.1.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.02.10.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.02.13.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/youtube-dl-2016.02.22.el_capitan.bottle.tar.gz (1M)
Would remove: /Library/Caches/Homebrew/zsh-5.1.1.el_capitan.bottle.tar.gz (2.5M)
Would remove: /Users/antony/Library/Logs/Homebrew/fontconfig (869B)
Would remove: /Users/antony/Library/Logs/Homebrew/openmotif (5 files, 2M)
Would remove: /Users/antony/Library/Logs/Homebrew/python (3 files, 101.9K)
Would remove: /Users/antony/Library/Logs/Homebrew/python3 (3 files, 105.3K)
Would remove: /Users/antony/Library/Logs/Homebrew/rename (52B)
Would remove: /Users/antony/Library/Logs/Homebrew/sshuttle (6.6K)
Would remove: /Users/antony/Library/Logs/Homebrew/xpdf (6 files, 238.4K)
==> This operation would free approximately 9.5G of disk space.
  • 3
    The -k tag (or something similar) would be lovely indeed. You should actually submit such idea to the Homebrew community (through their GitHub account I reckon) :) – AlessioX Mar 1 '16 at 21:48
2

Homebrew cleanup does not have a -k flag, nor is there any way to get Homebrew use the cleanup command to skip specific formulas.

There was a feature request in the Github Homebrew project, but it was rejected.

Create Your Own Tap

The advice then was to create your own tap. Since you are simply creating another version, use brew edit [formula] to modify the existing formula.

See for example the homebrew/php/php54 homebrew/php/php55 and homebrew/php/php56 formulas.

Create @ version formula

Homebrew itself supports multiple versions of some formulas, especially for widely used programming languages. For example, there are multiple @ versions of Ruby

$ brew search /^ruby*/
rubberband ✔        ruby-completion     ruby@1.9 ✔          ruby@2.2
ruby ✔              ruby-install        ruby@2.0            ruby@2.3
ruby-build ✔        ruby@1.8            ruby@2.1
homebrew/portable/portable-ruby          homebrew/portable/portable-ruby@2.2

Here is the ruby@1.9 formula

class RubyAT19 < Formula
  desc "Powerful, clean, object-oriented scripting language"
  homepage "https://www.ruby-lang.org/"
  url "https://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p551.tar.bz2"
  sha256 "b0c5e37e3431d58613a160504b39542ec687d473de1d4da983dabcf3c5de771e"
  revision 4

  bottle do
    sha256 "3db7c4d297998e6f53b10e35626bdf94f8db0836778ce8ef943846e1d5b35fbc" => :sierra
    sha256 "9c5dd40c620a597405e3c2d458bc9772ad1c661acf501b65f9e9d8871c300f7f" => :el_capitan
    sha256 "9334e46da0b55e3ea20bba27c49352b8b9f95674a5dea1691b5fd04625f23eed" => :yosemite
  end

  keg_only :versioned_formula

  option "with-suffix", "Suffix commands with '193'"
  option "with-doc", "Install documentation"
  option "with-tcltk", "Install with Tcl/Tk support"

  depends_on "pkg-config" => :build
  depends_on "readline" => :recommended
  depends_on "gdbm" => :optional
  depends_on "libyaml"
  depends_on "openssl"
  depends_on :x11 if build.with? "tcltk"

  def install
    args = %W[
      --prefix=#{prefix}
      --enable-shared
      --with-sitedir=#{HOMEBREW_PREFIX}/lib/ruby/site_ruby
      --with-vendordir=#{HOMEBREW_PREFIX}/lib/ruby/vendor_ruby
    ]

    args << "--program-suffix=#{program_suffix}" if build.with? "suffix"
    args << "--with-out-ext=tk" if build.without? "tcltk"
    args << "--disable-install-doc" if build.without? "doc"

    paths = [
      Formula["libyaml"].opt_prefix,
      Formula["openssl"].opt_prefix,
    ]

    %w[readline gdbm].each do |dep|
      paths << Formula[dep].opt_prefix if build.with? dep
    end

    args << "--with-opt-dir=#{paths.join(":")}"

    system "./configure", *args

    # Ruby has been configured to look in the HOMEBREW_PREFIX for the
    # sitedir and vendordir directories; however we don't actually want to create
    # them during the install.
    #
    # These directories are empty on install; sitedir is used for non-rubygems
    # third party libraries, and vendordir is used for packager-provided libraries.
    inreplace "tool/rbinstall.rb" do |s|
      s.gsub! 'prepare "extension scripts", sitelibdir', ""
      s.gsub! 'prepare "extension scripts", vendorlibdir', ""
      s.gsub! 'prepare "extension objects", sitearchlibdir', ""
      s.gsub! 'prepare "extension objects", vendorarchlibdir', ""
    end

    system "make"
    system "make", "install"
  end

  def post_install
    # Customize rubygems to look/install in the global gem directory
    # instead of in the Cellar, making gems last across reinstalls
    config_file = lib/"ruby/#{abi_version}/rubygems/defaults/operating_system.rb"
    config_file.unlink if config_file.exist?
    config_file.write rubygems_config

    # Create the sitedir and vendordir that were skipped during install
    ruby="#{bin}/ruby#{program_suffix}"
    %w[sitearchdir vendorarchdir].each do |dir|
      mkdir_p `#{ruby} -rrbconfig -e 'print RbConfig::CONFIG["#{dir}"]'`
    end

    # Create the version-specific bindir used by rubygems
    mkdir_p rubygems_bindir
  end

  def abi_version
    "1.9.1"
  end

  def program_suffix
    build.with?("suffix") ? "193" : ""
  end

  def rubygems_bindir
    "#{HOMEBREW_PREFIX}/lib/ruby/gems/#{abi_version}/bin"
  end

  def rubygems_config; <<-EOS.undent
    module Gem
      class << self
        alias :old_default_dir :default_dir
        alias :old_default_path :default_path
        alias :old_default_bindir :default_bindir
        alias :old_ruby :ruby
      end

      def self.default_dir
        path = [
          "#{HOMEBREW_PREFIX}",
          "lib",
          "ruby",
          "gems",
          "#{abi_version}"
        ]

        @default_dir ||= File.join(*path)
      end

      def self.private_dir
        path = if defined? RUBY_FRAMEWORK_VERSION then
                 [
                   File.dirname(RbConfig::CONFIG['sitedir']),
                   'Gems',
                   RbConfig::CONFIG['ruby_version']
                 ]
               elsif RbConfig::CONFIG['rubylibprefix'] then
                 [
                  RbConfig::CONFIG['rubylibprefix'],
                  'gems',
                  RbConfig::CONFIG['ruby_version']
                 ]
               else
                 [
                   RbConfig::CONFIG['libdir'],
                   ruby_engine,
                   'gems',
                   RbConfig::CONFIG['ruby_version']
                 ]
               end

        @private_dir ||= File.join(*path)
      end

      def self.default_path
        if Gem.user_home && File.exist?(Gem.user_home)
          [user_dir, default_dir, private_dir]
        else
          [default_dir, private_dir]
        end
      end

      def self.default_bindir
        "#{rubygems_bindir}"
      end

      def self.ruby
        "#{opt_bin}/ruby#{program_suffix}"
      end
    end
  ...
  ...
1

You could create a bash script similar to this

#!/bin/bash
brew_packages_to_be_cleaned=$(brew list -1 | grep -vi python | tr '\n' ' ')
brew cleanup $brew_packages_to_be_cleaned

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .