Last active
April 28, 2019 08:19
-
-
Save jeremyabbott/90594f61fb6beb5f3189c4313f269933 to your computer and use it in GitHub Desktop.
Remove old .NET Core versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dotnet --list-sdks # output looks like | |
# 2.1.500 [/usr/local/share/dotnet/sdk] | |
# awk '{print $2"/"$1}' # takes each line from stdin and prints out the 2nd column then "/" then the first column | |
# this gives us [/usr/local/share/dotnet/sdk]/2.1.500 | |
# sed 's/\]//' # replaces the first ']'. ']' has to be escaped with \ | |
# sed 's/\[//' # replaces the first '['. '[' has to be escaped with \ | |
# grep -Ev '2\.2\.102' # matches on 2.2.102 which was the latest SDK installed | |
# -E # enables extended regular expression syntax | |
# -v # inverts the match. So return anything that doesn't match | |
# xargs # allows us to pass standard in as an argument to rm -rf | |
# need sudo for rm -rf because these are protected directories | |
# rm # removes a file | |
# -r # means recusive (so delete everything in the directory, and also the directory itself) | |
# -f # remove file without prompting | |
# Sources | |
# 1. https://docs.microsoft.com/en-us/dotnet/core/versions/remove-runtime-sdk-versions?tabs=macos | |
# 2. https://stackoverflow.com/questions/3548453/negative-matching-using-grep-match-lines-that-do-not-contain-foo | |
# 3. https://stackoverflow.com/questions/11191475/command-line-piping-find-results-to-rm | |
# 4. http://www.grymoire.com/Unix/Sed.html | |
# remove all but the specified SDK version | |
dotnet --list-sdks | awk '{print $2"/"$1}' | sed 's/\]//' | sed 's/\[//' | grep -Ev '2\.2\.106' | xargs sudo rm -rf | |
# remove all runtimes except for latest 2.2 and 2.1 | |
dotnet --list-runtimes | awk '{print $3"/"$2}' | sed 's/\]//' | sed 's/\[//' | grep -Ev '2\.2\.4|2\.1\.6' | xargs sudo rm -rf | |
# The previous command removes some of the runtime files | |
# Still need to remove from another location, but now we can't get the runtime versions from standard out | |
# and dotnet --list-runtimes doesn't reveal this location. :( | |
ls /usr/local/share/dotnet/host/fxr | grep -Ev '2\.2\.4|2\.1\.6' | xargs sudo rm -rf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment