Introduction

This workshop introduces the Unix shell (Bash) as a practical tool for working with files, automating repetitive tasks, and building reproducible workflows. You will learn how the shell relates to your operating system and applications, and how to efficiently navigate directories, inspect and manipulate files, chain commands with pipes and filters, iterate with loops, and write simple shell scripts. By the end, you’ll be comfortable using core command-line patterns to explore data, transform text, and compose small, simple pipelines.

Learning Objectives

By the end of this workshop, you will know how to:

  • Understand what the shell is and when to use it.
  • Move around folders and find your way to files.
  • Make, copy, rename, and delete files and folders.
  • Join simple commands together to get the result you want.
  • Repeat actions on many files without retyping.
  • Save steps in small scripts so you can reuse them.
  • Search for files and for text inside files quickly.

Prerequisites

This lesson guides you through the basics of file systems and the shell. If you have stored files on a computer at all and recognize the word “file” and either “directory” or “folder” (two common words for the same thing), you’re ready for this lesson.

If you’re already comfortable manipulating files and directories, searching for files with grep and find, and writing simple loops and scripts, you probably want to skip this workshop.

Download files

You need to download some files to follow this lesson.

  1. Download shell-lesson-data.zip and move the file to your Desktop.
  2. Unzip/extract the file. You should end up with a new folder called shell-lesson-data on your Desktop.

Install software

If you do not already have the shell software installed, you will need to download and install it.

For a Mac computer running macOS Mojave or earlier releases, the default Unix Shell is Bash. For a Mac computer running macOS Catalina or later releases, the default Unix Shell is Zsh. Your default shell is available via the Terminal program within your Utilities folder.

  1. To open Terminal, try one or both of the following:

    • In Finder, select the Go menu, then select Utilities. Locate Terminal in the Utilities folder and open it.
    • Use the Mac ‘Spotlight’ computer search function. Search for: Terminal and press Return.
  2. To check if your machine is set up to use something other than Bash, type echo $SHELL in your terminal window.

  3. If your machine is set up to use something other than Bash, you can run it by opening a terminal and typing bash.

  1. The default Unix Shell for Linux operating systems is usually Bash. On most versions of Linux, it is accessible by running the Gnome Terminal or KDE Konsole or xterm, which can be found via the applications menu or the search bar.
  2. If your machine is set up to use something other than Bash, you can run it by opening a terminal and typing bash.

Computers with Windows operating systems do not automatically have a Unix Shell program installed. In this lesson, we encourage you to use an emulator included in Git for Windows which gives you access to both Bash shell commands and Git or Visual Studio Code which gives you access to Bash shell commands.

Option 1: Git for Windows

  1. Download and install Git for Windows from gitforwindows.org.
  2. During installation, ensure that the option to use Git from the Windows Command Prompt is selected.
  3. After installation, open Git Bash from the Start menu.

Option 2: Visual Studio Code

  1. Download and install Visual Studio Code from code.visualstudio.com.
  2. Install the “Remote - WSL” extension from the Extensions Marketplace.
  3. Open a new terminal in VS Code, and select the Bash shell.

Note for Peter Mac Windows Users: If you need to install new software on Peter Mac Windows computers, you will need to Create a Snow Ticket for installation.

Course Outline

Time Lesson Questions
5 Introducing the Shell What is a command shell and why would I use one?
30 Navigating Files and Directories How can I move around on my computer?
How can I see what files and directories I have?
How can I specify the location of a file or directory on my computer?
30 Working With Files and Directories How can I create, copy, and delete files and directories?
How can I edit files?
20 File Permissions How does Linux know who can access files?
How can I see what permissions a file has?
How can I set or change the permissions on a file?
25 Pipes and Filters How can I combine existing commands to produce a desired output?
How can I show only part of the output?
40 Loops How can I perform the same actions on many different files?
30 Shell Scripts How can I save and re-use commands?
25 Finding Things How can I find files?
How can I find things in files?
20 AWK for Text Processing How do I print specific columns from a text table?
How can I use patterns to select only certain lines in a file?
How do I count lines or matched lines in a file?

Credits and Acknowledgement

These content were adapted from the following course materials: