Overview

Workshop

This workshop is the hands-on follow-up to our just do git — shell presentation.

Two ideas to take home:

  1. The file explorer and the terminal show the same files. They are just two windows into your computer.
  2. Every command you type launches a program. Typing its name is like double-clicking its icon.

⚠️ Safety first: This workshop never deletes anything, and every writing exercise happens inside a freshly created playground folder. Commands that can overwrite files are marked with ⚠️.

Always read the warning before you run the command!

Stuck? Every task is solved on the solutions page, and all commands are in the cheat sheet.

❓ Forgot an option? Ask the program itself: CMD --help for a short summary, man CMD for the full manual (no man in Git Bash).

Setup: open a terminal

  1. Open a terminal:

    • Linux: search for terminal or console (it is already installed)
    • macOS: press cmd + space, type Terminal, press Enter
    • Windows: download and install Git for Windows (includes Git Bash), then open Git Bash from the Start menu

    Note: Windows also ships PowerShell and cmd. Those are different shells, not the UNIX shell! The commands in this workshop only work in Git Bash.

    Note: macOS’ terminal uses zsh, a close cousin of bash. Everything here works exactly the same there.

  2. The prompt is the line where you type:

     user@gnugen:~ $
    

    In Git Bash it looks like this:

     user@DESKTOP-123 MINGW64 ~
     $
    
    • user is your username (you!)
    • ~ is your home folder, the folder where you start
    • after the $ you type a command and press Enter to run it

If you use Git Bash (Windows): Git Bash is a UNIX world on Windows, you are not running Linux. Your Windows folder C:\Users\you appears as /c/Users/you in the terminal. WSL (Linux inside Windows) also exists. There the disk is mounted at /mnt/c/Users/you. This workshop uses Git Bash, but can be completed in WSL if you take the different disk mount into account.

The terminal as a file explorer

Your first task: open your file explorer (Windows: File Explorer, macOS: Finder, Linux: Files / Dolphin / …) and put its window next to the terminal, both showing your home folder.

On Windows, Git Bash starts in your home folder ~ = /c/Users/you = C:\Users\you.

In File Explorer navigate to This PC → Local Disk (C:) → Users → your name.

  1. Find out where you are in the terminal. Which command could do that? Try it!
👀 Need a hint for 1? - Click here to reveal a hint

The command is pwd (print working directory). It prints the folder you are currently in.

pwd
  1. List the files in this folder:

     ls
    

    Question: Compare the output with the file explorer. What do you see?

  2. Also show the hidden files (their names start with a dot, like .gitconfig):

     ls -a
    

    Question: What is new compared to plain ls?

    In the file explorer, hidden files only appear after turning on show hidden files (Windows: View → Show → Hidden items; Linux/macOS: ctrl + h in many file managers).

Commands are programs

When you type ls and press Enter, your shell launches the program ls. That is all a command is: a program, like Firefox or the file explorer. Typing its name is the same as clicking its icon.

  1. Run these three programs (one at a time):

     whoami
     date
     git --version
    

    Question: Before running: what will whoami print? And date? Guess first.

    (git is a version control program, you will meet it in one of our other workshops. If it is not installed on your Linux, you get command not found, that is fine too.)

  2. Now launch a GUI program from the terminal, the file explorer itself:

     explorer .
    

    (Windows, Git Bash; Linux: xdg-open ., macOS: open .)

    Question: What opened, and where?

  3. The same trick works for any program. On Linux, if Firefox is installed:

     firefox
    

    On Windows (Git Bash), try the same with Notepad:

     notepad
    

    On macOS, launch Safari like this:

     open -a Safari
    

    Only programs on the PATH start this way. The same rule on every system.

Moving around

You already know the file explorer navigation: double-click a folder to enter, press the up button to leave. In the terminal you do the same with cd (change directory).

Paths come in two flavours:

  • absolute: starts at the root /, works from anywhere: /home/user/Documents (Git Bash: /c/Users/user/Documents)
  • relative: starts from where you are: Documents

Shortcuts that work everywhere:

  • ~: your home folder
  • ..: the parent folder (one level up)
  • .: the current folder
  1. Enter your Documents folder and check where you are:

     cd Documents
     pwd
    

    Question: Before pwd: which folder do you expect?

  2. Go back up and confirm:

     cd ..
     pwd
    

    Question: Where are you now?

  3. Three ways to get home. Do they all end in the same place?

     cd ~
    
     cd
    
     cd /home/user
    

    (the last one is an absolute path; Git Bash: cd /c/Users/user)

  4. Bonus: cd - jumps back to the previous folder, like the back button:

     cd Documents
     cd -
    

    Question: Run cd - again. Where does it take you?

💡 Tip: press Tab while typing a name and the shell completes it. cd Doc + Tab becomes cd Documents/. Fewer typos, faster everything.

Create a folder and edit a file

Everything below happens inside your own playground folder. Nothing can go wrong in the rest of your files.

  1. Create a new folder (no spaces in the name, they make shell life harder):

     mkdir gnugen-shell-workshop
    

    Question: Will the folder also appear in the file explorer? Guess, then check (press F5 to refresh).

  2. Step into it and check you are really inside:

     cd gnugen-shell-workshop
     pwd
    

    Question: What will pwd print?

  3. Create an empty file:

     touch notes.txt
    

    Question: Check the file explorer. What changed?

  4. Now write something in it, inside the terminal, with the nano editor:

     nano notes.txt
    
    • type a few lines, e.g. I can edit files in the terminal!
    • the shortcuts are always shown at the bottom; ^ means ctrl
  5. Verify in the file explorer, double-click notes.txt and make sure your text is there!

Copy, rename and move

⚠️ Warning: cp and mv overwrite an existing destination file silently, without asking! If the destination name already exists, it is replaced. Always double-check your file names!

  1. Make a copy of your notes (the terminal way to copy & paste):

     cp notes.txt backup-of-notes.txt
     ls
    

    Question: How many files will ls show? Guess before running.

  2. Rename the copy (renaming is moving a file to a new name):

     mv backup-of-notes.txt my-backup.txt
     ls
    

    Question: Where did backup-of-notes.txt go?

  3. Create a subfolder and move the file into it (the terminal way to drag & drop):

     mkdir archive
     mv my-backup.txt archive/
     ls
     ls archive
    

    Question: Check the file explorer. Where is my-backup.txt now?

Note about deleting: unlike the file explorer’s trash bin it has no trash or undo. Because of that, this workshop deliberately excludes it, view the cheat sheet for more info about the rm command.

Pipes and redirection

Two small superpowers of the shell.

  1. echo:

     echo "hello from the shell!"
    

    Question: Before running: what do you think echo does?

  2. With > you send that output into a file instead of the screen:

     echo "hello from the shell!" > message.txt
    

    ⚠️ Warning: > overwrites the target file (message.txt) without asking.

    Read it back and double-check in the file explorer:

     cat message.txt
    

    Question: What is in message.txt afterwards?

  3. >> appends at the end instead of overwriting:

     echo "one more line" >> message.txt
     cat message.txt
    

    Question: How does the output differ from the last cat?

  4. The pipe | chains programs: the output of the first becomes the input of the second:

     ls | wc -l
    

    Question: Count the files in this folder in the file explorer first (it shows its count as “x items”). What will ls | wc -l print? Run and compare.

Variables

  1. A variable stores a value in your current session (no spaces around the =!):

     name="ado"
     echo $name
    

    Question: Before you execute echo $name: what do you think will appear? What appears after executing?

  2. Change the value and repeat:

     name="gnugen"
     echo $name
    

    Question: And now?

  3. Environment variables are shared with every program you launch. One you will meet everywhere is HOME, your home folder:

     echo $HOME
    

    Question: What do you expect? How does it relate to ~?

  4. See all of them:

     env
    

    Question: Do you find your username in there?

    On Git Bash the list is long and contains Windows variables too.

Errors and return codes

Programs give feedback in two ways: what they print, and a return code they hand back when they finish. Silence usually means success. How does a program say something went wrong?

  1. Try to read a file that does not exist (don’t worry, reading a missing file breaks nothing):

     cat doesnotexist.txt
    

    Question: What do you think happens?

  2. Ask for the return code:

     echo $?
    

    $? holds the return code of the last command.

    Question: What number appeared? The rule: 0 = success, anything else = error.

  3. Try a typo:

     lss
    
     echo $?
    

    Question: Before running: what do you think echo $? will show?

  4. And for contrast, a successful command:

     cat message.txt
     echo $?
    

    Question: What code does a working command return?

Getting help

You do not have to memorize anything. Every program can explain itself. Two ways to ask:

  1. The manual, man (Linux and macOS):

     man ls
    

    A full-screen documentation page opens: what the program does, all its options. Scroll with the arrow keys, quit with q.

    Git Bash does not include man, you would get command not found. Use the next trick there.

  2. The quick help (Linux and Git Bash):

     ls --help
    

    Most programs print a compact summary of their options.

    Question: Find the option that also shows hidden files. Which one is it?

    On macOS some programs ignore --help. Use man there.

  3. Bonus round: what do you think man man shows? 😉

💡 Tip: q quits any full-screen terminal program (man, less, …).

Bonus: permissions

Files carry permissions: who may read, write, or execute them.

  1. In your playground folder:

     ls -l
    
     -rw-r--r-- 1 user user  34 Oct  4 21:00 message.txt
     -rw-r--r-- 1 user user  34 Oct  4 20:55 notes.txt
     drwxr-xr-x 2 user user   0 Oct  4 20:58 archive
    

    (in Git Bash the layout may look slightly different, that is fine)

  2. How to read it:

    • first character: - file, d directory
    • then three groups of three: r = read, w = write, x = execute, once for the owner (user), the group, and everyone else
    • so -rw-r--r-- means: owner may read & write, everyone else may only read

    The file explorer shows the same info: right-click a file, Properties → Security (Windows) or Properties → Permissions (Linux).

Cleanup

Want to get rid of the playground folder gnugen-shell-workshop? Do it the safe way today: drag it to the trash in the file explorer (and empty the trash if you really want it gone).

If you made it this far: congrats!

From here:

  • keep the cheat sheet at hand and experiment on your own files
  • when stuck, peek at the solutions
  • and then use the shell for your own projects!

Survey

We value your feedback!

To make the workshop even better next year, feel free to fill out this survey so we know if you liked the workshop and how we can improve it.

It only takes 2 minutes to fill out and helps us a lot! :))