Command Line Interface#
A Command Line Interface (CLI) is a method of interacting with a computer that involves individual lines of text. These so-called command lines can be entered manually by the user, as well as written in a text-based file and passed on to a computer or application for automatic entry and execution. The alternative to a CLI is a Graphical User Interface (GUI).
Why use a CLI?
A few of the main reasons for using a CLI in engineering work are:
rudimentary tasks are easily automated and repeated (e.g., copying, moving, renaming files and folders)
some software does not have a GUI
a CLI can easily be opened on any modern laptop and can be much faster than using a GUI
For example, once you can use the CLI you will probably find it much easier than using a GUI to navigate to a working directory on your computer, create and activate a computing environment for your project and open and begin working in your chosen IDE.
There is a long history of CLI’s and many different types; a brief overview and set of examples are provided on this page.
Definitions and Terms#
There are various terms to be aware of, but we will only give a brief explanation here (see this tutorial for a more detailed explanation):
Terminal: a piece of hardware for entering data into a computer. How we did it in the “old days” (the Wikipedia page has a few examples).
Console: similar to a terminal, but adds hardware, interaction and a few other things (if you want to understand the difference, try reading this)
Shell: an application that allows a user to write commands and enter data that can be translated into commands and data that can be executed by the operating system and hardware on a given computer; in short, this is how your instructions can be interpreted by any computer, regardless of hardware or operating system. A shell generally has two methods for interaction, a graphical user interface (GUI) or a command line interface (CLI).
Command Line Interface: a method of interacting with a computer that involves typing lines of text into an interface; modern CLI’s are implemented in shell applications. Visit the CLI Wikipedia page for an exhaustive overview of CLI’s.
Now that these have been defined, you might realize that most of your life you have probably used a GUI to interact with your computer (remember, your mobile phone is also a computer!). This page is about using the alternative shell interface: a CLI!
You will hear many people and see software that use the terms above interchangeably (for example, VS Code uses the term “terminal” for all CLI’s), but in reality usage of the term terminal or console today generally refers to a shell with a CLI. We recommend sticking to the term command line interface (CLI), or simple the command line as this is platform independent and captures what we are physically doing with regards to the content in this book: entering and executing commands via a CLI.
Examples of CLI#
There are many types of modern CLI’s that you may come across, here is a short list to give you an idea of their names and a few observations about each one:
Terminal: the standard CLI on a Mac OS
Command Prompt: one of several CLI’s commonly used on Windows OS
PowerShell: one of several CLI’s commonly used on Windows OS. Notorious for having a syntax and set of commands that is different from most other CLI’s (we recommend you avoid this one, if possible)
Anaconda Prompt: a custom CLI that builds on other CLI’s. For example, on Windows OS you can find a Command Prompt and PowerShell versions, depending on your preference
Bash: widely used on Linux systems
Git Bash: a CLI that comes with the Git software distribution that is the easiest way to get Unix style commands on a Windows OS
Tip
Many CLI’s use UNIX style syntax and commands. UNIX is a family of operating systems that were developed in the 1970’s and influenced many other computer OS’s.
Mac and Linux OS’s use UNIX style commands, but unfortunately the CLI’s’that are available by default on Windows OS do not. This can make it more difficult to use the CLI for Windows users, especially because the vast majority of online documentation and open source CLI tools available today use UNIX-like syntax and commands.
It is easy to work around this issue, however, for example:
it is easy to find the equivalent commands between UNIX and Windows CLI’s _once you are aware that there is a difference) (see examples below)
it is possible to get UNIX style CLI’s on Windows OS (e.g., Git Bash)
Basic CLI Skills: Cheat Sheets#
The tables below will give you commonly used commands on Mac and Windows OS’s
Mac (UNIX Style commands) |
Windows (Command Prompt) |
|
---|---|---|
Present Working Directory |
|
|
List content of the present working directory |
|
|
Change: Change Directory |
|
|
Touch: Creates a new file or updates the timestamp |
touch {filename} ( |
touch {filename} ( |
Create new directory |
mkdir {directory_name} ( |
mkdir {directory_name} ( |
Copy: Copies file or directory |
cp {source} {target} ( |
cp {source} { target} ( |
Moves a file or directory |
mv {source} {target} ( |
mv {source} {target} ( |
Removes: Removes file |
rm {filename} ( |
rm {filename} ( |
Removes: Removes directory |
rmdir {directory_name} ( |
rmdir {directory_name} ( |
Clear up terminal |
|
|
Python
Mac (UNIX Style commands) |
Windows (Command Prompt) |
|
---|---|---|
Verifying and version |
|
|
Opening Python shell |
|
|
run python files |
python3 {py_file_name} |
py3 {py_file_name} |
Open python file in VS Code |
code {py_file_name} |
code {py_file_name} |
Tip
Depending on your computer settings, you may need to use python
or python3
to call the interpreter. Usually one or the other words by default on Mac, as it comes pre-installed with Python. For Windows OS, we recommend you use the Anaconda Command Prompt, as it was installed along with Python, which should be findable as long as you added conda.exe
to your PATH
environment variable.
Links to other Cheat Sheets#
Here are links for more detailed command line cheat sheets: