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 or terminal emulator.

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, so we will not give specific instructions for Linux.

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 shell for macOS and several Linux distributions.

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 in the bootcamp (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

cd

cd

mv

mv

pwd

pwd

ls -al

ls -Hidden

rm -rf

del -Force -Recurse .\mydirectory

more

more

less

Does not exist

head -5 myfile.txt

gc myfile.txt -head 5

tail -5 myfile.txt

gc myfile.txt -tail 5

cat ./dir/myfile.txt

!type "dir\myfile.txt"

Copyright note: In addition to the copyright shown below, this recitation was developed based on materials from Axel Müller.