sudo apt --installed list | grep "dotnet"
# sample result of this command
dotnet-apphost-pack-3.0 dotnet-hostfxr-3.1 dotnet-runtime-deps-5.0
dotnet-apphost-pack-3.1 dotnet-hostfxr-5.0 dotnet-sdk-5.0
dotnet-apphost-pack-5.0 dotnet-runtime-5.0 dotnet-targeting-pack-3.0
dotnet-host dotnet-runtime-deps-2.2 dotnet-targeting-pack-3.1
dotnet-hostfxr-2.2 dotnet-runtime-deps-3.0 dotnet-targeting-pack-5.0
dotnet-hostfxr-3.0 dotnet-runtime-deps-3.1
$ sudo apt-get remove --purge dotnet-*3*
# get installed dotnet information
dotnet --info
# remove sdk and runtime based on installed version ( in my case 5.0 )
sudo apt remove --purge dotnet-sdk-5.0
sudo apt remove --purge dotnet-runtime-5.0