Introducing the Shell
Overview
Questions
- What is a command shell and why should we use it?
Objectives
- Explain how the command shell works with the keyboard, screen, operating system, and user programs.
- Explain when and why to use a command shell instead of a graphical user interface (GUI).
Basics
People interact with computers in many ways: keyboard, mouse, touch screen, or voice. The most common interface on personal computers is a graphical user interface (GUI), where you give instructions by clicking and picking menu items.
A GUI is easy to learn, but it does not scale well for repetitive work. Imagine copying the 3rd line from 1,000 text files across 1,000 folders into a single file. Doing that in a GUI takes hours and invites mistakes. The Unix Shell solves this: it is both a command-line interface (CLI) and a scripting language, so you can automate repetitive tasks in seconds.
The Shell
A shell is a program where you type commands to run other programs—from complex modeling tools to simple tasks like creating an empty folder. The most popular Unix shell is Bash (the Bourne Again SHell, based on Stephen Bourne's shell). Bash is the default shell on most Unix/Linux systems and in Unix toolkits for Windows (such as Git Bash).
Learning the shell takes some effort because CLI options are not shown on screen like GUI menus. Still, a small set of core commands goes a long way.
Shell grammar lets you combine existing tools into pipelines for large data tasks. You can save command sequences as scripts to make your workflow repeatable.
The command line is also the standard way to work with remote servers, clusters, cloud systems, and high-performance computing (HPC) machines.
Getting Started
When you first open a shell, you see a prompt showing that the shell is ready for input:
$
Shells often use $ as the prompt (it may look different depending on your setup). In these lessons, the prompt is shown as $. Do not type $—only type the command after it, then press Enter to run it.
Next to the prompt is a cursor showing where your typed text will appear.
Your real prompt often includes your username and hostname before $, for example:
nguyen@localhost $
The extra text before $ does not change how the lessons work; just focus on the $ character.
Try your first command, ls (short for list), to display the contents of the current folder:
$ ls
Desktop Downloads Movies Pictures
Documents Library Music Public
command not found Error
If the shell cannot find a program matching the command you typed, it prints an error:
$ ks
ks: command not found
Key Points
- A shell is a program that reads commands and runs other programs.
- This lesson uses Bash, the default shell on many Unix systems.
- You run programs in Bash by typing commands at the command prompt.
- Key advantages: fast actions, automation of repetitive tasks, and easy access to remote machines.
- Main challenge for beginners: learning which commands to run and how to combine them.