How to stop .NET Core from collecting data to protect privacy?

Short answer:

Issuing this command should disable telemetry:

export DOTNET_CLI_TELEMETRY_OPTOUT=1

More details:

This is the output from running the dotnet new as the first command.

Welcome to .NET Core!
---------------------
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
Telemetry
--------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.
Decompressing 100% .... ms
Expanding 100% .... ms

More information can be obtained from the sources and the pull request for telemetry feature

DOTNET_CLI_TELEMETRY_OPTOUT

Specifies whether data about the .NET Core tools usage is collected and sent to Microsoft. true to opt-out of the telemetry feature (values true, 1 or yes accepted); otherwise, false (values false, 0 or no accepted). If not set, it defaults to false, that is, the telemetry feature is on.

It is good to know where .NET Core creates its cache.