What is the command line?
Perhaps the first step toward really empowering you to command your computer to do whatever you will is to learn how to use the command line. This lesson provides a brief introduction to command line skills.
What is a shell?
A shell is a program that takes commands from files or entered interactively through the keyboard and passes them on to the operating system to be executed. A shell is accessed through a terminal (emulator). Where you would normally execute a command by clicking on a button (e.g. open the Downloads folder by double-clicking on it), a shell lets you perform the same operations by typing commands (e.g. cd Downloads
).
We will use JupyterLab’s terminal in this tutorial. However, you need not limit yourself to using this. If you are using macOS, you can use the Terminal application. For a Mac, you can fire up the Terminal application. It is typically in the /Applications/Utilities
folder. Otherwise, hit ⌘-space bar and type terminal
in the search box, and select the Terminal Application. For Windows, you can use PowerShell, which you can launch through the Start
menu. If you are using Linux, it’s a
good bet you already know how to navigate a terminal, but, in most cases, hit the Super-key and type terminal
.
A very brief historical overview
Ken Thompson of Bell Labs developed the predecessor to the modern shell for the first release of UNIX in 1971. In 1977, Stephen Bourne introduced the Bourne shell (sh
) which added the ability to invoke scripts (small reusable programs) from within the shell. The Bourne shell remains relevant. In some cases it is still the default root shell. Shortly afterwards, the C shell (csh
) was developed which made use of a C-like scripting language. tcsh
is built on csh
and is still very
common. bash
, the Bourne again shell was developed by Brian Fox to replace the Bourne shell. It adds many useful features to sh and is the default for several Linux distributions. It used to be the default for macOS until Catalina (2019), when it was replaced by zsh
.
Windows vs. macOS/Linux
Windows 10 enables you to also use bash
, but you need to activate the Windows Subsystem for Linux. We will not use bash
for Windows users (unless you want to), but will instead use PowerShell, which is also the default shell in JupyterLab’s terminal for Windows users. For the simple command line operations we will do in here, PowerShell is almost always sufficient and the syntax is the
same. This cheatsheet is a useful reference for comparing bash
and PowerShell commands.
In what follows below, we will show the bash
commands and sometimes provide commentary for Windows users. Here is a brief table comparing bash
to PowerShell commands.
Bash |
PowerShell |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Does not exist |
|
|
|
|
|
|
As you can see every command takes some arguments, which specify flags (usually when preceded by -
or --
) or files on which to act. The arguments are specified on the same line of the command and separated by spaces. That is to say, a space means “cue new argument”.
Copyright note: In addition to the copyright shown below, this recitation was developed based on materials from Axel Müller.