Back to Tutorials

Using Shells in Computer Programming

What is a Command-Line Interface?

A Command-Line Interface (CLI) is a broad term that encompasses any text-based interface where users can interact with software or the operating system by typing commands. A CLI is composed of both a terminal and a shell.

The terminal is an interface for interacting with the shell. It allows you to type commands and display the output, but it doesn't interpret or execute the commands itself. The terminal simply sends them to the shell for processing.

The shell processes the commands you enter in the terminal. The shell parses the command, determines what needs to be done, and either executes built-in commands or passes instructions to the operating system to run external programs.

To simplify: The terminal is the interface (i.e., frontend), and the shell is the command interpreter (i.e., backend).

The terms CLI, terminal, shell, and console are often used interchangeably in programming. Examples of shells for operating systems include PowerShell and Command Prompt (for Windows), Bash (for Linux), and Z shell (for macOS). An example of a shell for software is the SQL Shell (psql) used with the PostgreSQL database.

What is PowerShell and Command Prompt?

PowerShell and Command Prompt (a.k.a. CMD) are both CLIs for Windows. CMD is the legacy CLI on Windows. It has a simple text-based interface that allows users to execute basic system commands and run batch scripts. On the other hand, PowerShell is a more modern, powerful command-line shell introduced in 2006 to replace CMD as the primary CLI for Windows. Unlike CMD, it supports automation, object manipulation, and system administration tasks on a much deeper level.

Opening Windows Shells

To open PowerShell on Windows, type powershell in the Windows Search. For Command Prompt, type cmd. If you have the Windows Subsystem for Linux (WSL) installed, you can access Bash by typing the name of your installed Linux distributions. For example: "Ubuntu". This will open Ubuntu in its own terminal.

Take Note: In all of my tutorials, I will use Windows as the operating system and PowerShell as the default shell.

Basic Commands for the Command Prompt, PowerShell, and Bash

Here are some essential commands that you'll frequently use in your programming:

Navigating Directories

Action Command Prompt/ PowerShell Bash
Change directory cd [directory] cd [directory]
Move Up One Level cd .. cd ..
List Files and Directories dir dir
Move Down into a Directory cd [directory] cd [directory]

Creating, Reading, Updating, and Deleting a Folder

Action Command Prompt/ PowerShell Bash
Create Folder mkdir [folder_name] mkdir [folder_name]
Read Folder (List Contents): dir dir
Update Folder (Rename) ren [old_name] [new_name] mv [old_name] [new_name]
Delete Folder rmdir [folder_name] rm \-r [folder_name]

Creating, Reading, Updating, and Deleting a File

Action Command Prompt/ PowerShell Bash
Create File echo > [file_name.py] touch [file_name.py]
Read File type [file_name.py] cat [file_name.py]
Update File notepad [file_name.py] nano [file_name.py]
Delete File del [file_name.py] rm [file_name.py]