Terminal & Command Line Basics
cd, ls, mkdir, environment variables and PATH across shells.
Terminal and Command Line Basics for .NET Developers
The terminal is an essential tool for developers because it allows you to interact with your operating system using commands instead of relying entirely on graphical interfaces. For .NET developers, the command line is useful for creating projects, restoring packages, building applications, running tests, and managing development environments.
Learning basic terminal commands also makes it easier to follow technical documentation, work with Git, and automate repetitive tasks. Whether you use Windows PowerShell, Command Prompt, Git Bash, or a Linux terminal, understanding directories, environment variables, and PATH will help you work more confidently.
1. What Is a Terminal and a Shell?
A terminal provides an interface for entering commands and viewing their output. A shell is the program that interprets those commands and executes them.
On Windows, common shells include PowerShell and Command Prompt. Git Bash provides a Bash-like environment, while Linux and macOS commonly use Bash or Zsh.
Although these shells perform similar tasks, their commands and syntax are not always identical. For example, ls works in PowerShell and Bash, but traditional Windows Command Prompt uses dir to list directory contents.
2. Essential Commands: cd, ls, and mkdir
Three commands you'll frequently use are cd, ls, and mkdir. They help you navigate folders and organize your development projects.
cd — Change Directory
The cd command changes your current working directory.
cd MyProject
This moves into the MyProject directory inside your current location.
To move one directory upward, use:
cd ..
To navigate to a specific location in PowerShell or Bash, provide its path:
cd C:\Projects\MyApp
In Bash, the equivalent might be:
cd /home/user/projects/MyApp
Your current working directory matters because commands such as dotnet build and dotnet run generally operate on the project or solution available from that location.
ls — List Directory Contents
The ls command displays files and folders in the current directory. It is commonly used in Bash and is also available as an alias in PowerShell.
ls
In PowerShell, you can also use:
Get-ChildItem
In Windows Command Prompt, use:
dir
Listing directory contents helps you locate files such as Program.cs, project files ending in .csproj, and solution files ending in .sln or .slnx.
mkdir — Create a Directory
The mkdir command creates a new directory.
mkdir MyDotNetProjects
You can then navigate into the directory and create a .NET console application:
cd MyDotNetProjects
dotnet new console -n HelloDotNet
cd HelloDotNet
dotnet run
These commands create a project, enter its directory, and execute the application using the .NET CLI.
3. Understanding Environment Variables
Environment variables are named values maintained by the operating system or process environment. They allow applications and development tools to access configuration without embedding every setting directly into source code.
For example, an application might read an environment variable to determine its execution environment, while a command-line tool might use environment variables to locate configuration files or SDK installations.
Common examples include:
PATH: Directories searched when locating executable commands.HOME: The user's home directory in many Unix-like environments.USERPROFILE: The current user's profile directory on Windows.DOTNET_ROOT: A variable that can identify a .NET installation location for certain tools and hosting scenarios.ASPNETCORE_ENVIRONMENT: Commonly used to identify an ASP.NET Core application's environment, such asDevelopmentorProduction.
Reading environment variables
In PowerShell:
$env:ASPNETCORE_ENVIRONMENT
In Windows Command Prompt:
echo %ASPNETCORE_ENVIRONMENT%
In Bash:
echo "$ASPNETCORE_ENVIRONMENT"
If a variable has not been defined, the command may return an empty value.
Environment variables are particularly useful when configuring local development tools and separating application settings across environments.
4. Understanding PATH
PATH is an environment variable containing a list of directories that the operating system or shell searches when you execute a command without specifying its full path.
For example, when you run:
dotnet --version
your shell must locate the dotnet executable. If the directory containing that executable is included in the relevant PATH configuration, the command can run without requiring its full location.
Checking PATH
In PowerShell:
$env:Path
In Windows Command Prompt:
echo %PATH%
In Bash:
echo "$PATH"
What happens when PATH is incorrect?
If a command such as dotnet is not recognized, possible causes include an incomplete installation, an incorrect PATH configuration, or a terminal that has not loaded updated environment settings.
Start by checking the installation:
dotnet --info
If the command fails, verify that the .NET SDK is installed and that the executable is accessible through PATH. Restarting the terminal after changing environment variables may also be necessary.
Important: Avoid replacing the entire PATH value when adding a new directory. Preserve existing entries, because other applications and development tools may depend on them.
5. Working with Different Shells
The same development task can require slightly different commands depending on the shell you use.
| Task | PowerShell | Command Prompt | Bash |
|---|---|---|---|
| List files | ls | dir | ls |
| Change directory | cd folder | cd folder | cd folder |
| Create directory | mkdir folder | mkdir folder | mkdir folder |
| Read PATH | $env:Path | echo %PATH% | echo "$PATH" |
Read an environment variable named MY_VAR | $env:MY_VAR | echo %MY_VAR% | echo "$MY_VAR" |
| Print current directory | pwd | cd | pwd |
PowerShell supports several familiar command aliases, but it also has its own scripting language and environment-variable syntax. Bash uses Unix-style paths and shell conventions. Understanding these differences helps prevent errors when switching between terminals.
6. Useful Commands for .NET Development
Once you understand basic navigation, these .NET CLI commands become part of your everyday development workflow.
| Command | Purpose |
|---|---|
dotnet --version | Displays the selected .NET SDK version. |
dotnet --info | Displays detailed information about the .NET installation and environment. |
dotnet new console | Creates a console application in the current directory. |
dotnet restore | Restores project dependencies. |
dotnet build | Builds the project or solution. |
dotnet run | Builds and runs a project when required. |
dotnet test | Runs tests for supported test projects. |
dotnet --list-sdks | Lists installed .NET SDKs. |
These commands let you perform many common development tasks without opening a graphical IDE. They are also useful in automated build pipelines and CI/CD workflows.
Key Takeaways
- A terminal provides a command-line interface, while a shell interprets and executes commands.
cd,ls, andmkdirhelp you navigate folders and organize projects.- Environment variables provide configuration values to applications and development tools.
- PATH helps the operating system or shell locate executable commands.
- PowerShell, Command Prompt, and Bash use different syntax for some operations.
- The .NET CLI makes it possible to create, build, run, and test applications directly from the terminal.
Frequently Asked Questions
What is the difference between a terminal and a command prompt?
A terminal is an interface for interacting with a command-line program. Command Prompt is a specific Windows command-line shell, while PowerShell and Bash are other shells with different commands and scripting capabilities.
What does the cd command do?
The cd command changes the current working directory. It helps you navigate to the folder containing your .NET project before running commands such as dotnet build or dotnet run.
What is the difference between PATH and an environment variable?
An environment variable is a named value available to a process. PATH is a specific environment variable that contains directories searched when locating executable commands.
Why is dotnet not recognized in the terminal?
This error commonly occurs when the .NET SDK is not installed, the dotnet executable cannot be found through PATH, or the terminal has not loaded updated environment settings. Verify the SDK installation and check your PATH configuration.
Do PowerShell and Bash use the same commands?
Some commands, such as cd, ls, and mkdir, work in both environments. However, environment-variable syntax, scripting features, file paths, and other commands can differ.
Related Topics
- Visual Studio 2026: Beginner's Guide
- VS Code and C# Dev Kit
- Introduction to .NET and C#
- .NET SDK and CLI Fundamentals
- Git and GitHub Basics
- Environment Configuration in ASP.NET Core
Last updated 10/26/2026
Your notes
Sign in to save personal notes on this topic — they'll sync across your devices.
Was this tutorial helpful?
Help us create more free learning resources. Learn more
