In this lesson we'll learn about the shell, a command-based interface for interacting with the operating system of a computer.
Learning objectives:
- Locate and open the terminal application on your computer
- Know what a file system is
- Understand basic shell commands for manipulating files
- Get exposure to some intermediate/advanced commands
- Know where to get help, or more information
A terminal is an application that allows a user to communicate with the operating system of a computer through terse text commands.
- JupyterLab: Terminal app in the Launcher
- Linux: terminal or xterm
- macOS: Terminal.app (built-in) or iTerm.app
- Windows: Git Bash in Git for Windows
At this time, if you haven't already done so, open a terminal.
Because it works. Really well.
When you develop skill with shell commands in a terminal, you can do filesystem-specific tasks--moving, copying, renaming, deleting files and directories--much faster than with a graphical application.
By analogy, think of keyboard shortcuts on your computer:
if you want to change from one application to another,
it's much faster to hit Cmd-Tab
(on macOS; Alt-Tab
on Linux and Windows)
than it is to use a mouse to go find the other application window.
Commands tend to be terse to the point of being cryptic,
not that different from texting shorthand:
instead of brb, it's cd
;
instead of ttyl, it's rm
, etc.
And it's done for the same reason: speed.
Commands can also be gathered into scripts that can be executed as a single unit. With a script, you can automate a repetitive task. Scripts are marvelous for data processing pipelines, and can improve reproducibility. We won't cover scripting here, but there's more information in Software Carpentry's The Unix Shell lesson, on which this lesson is based.
The command prompt (or shell prompt) is where we enter commands into a terminal.
It's typically denoted with a dollar sign $
.
We use a terminal in a read-evaluate-print loop (REPL); that is, when we enter a command at the prompt, the shell:
- reads the command
- evaluates the command
- prints output to the terminal
This process is repeated every time we enter a command.
This lesson on the shell continues in the following sections:
This lesson is designed to run on EarthscapeHub.
- Five reasons why researchers should learn to love the command line
- The Software Carpentry shell lesson
- The Bash Guide for Beginners from the Linux Documentation Project
- The GNU Bash Manual in various formats