Overview

Solutions

Solutions for the shell workshop. Try each task yourself first!

โš ๏ธ Reminder: the workshop never deletes anything and every writing exercise happens inside your gnugen-shell-workshop folder. The same is true here: no dangerous commands, everything is copy-paste safe.

The example outputs below use the username user. Your username, filenames and folder contents will (and should!) look different.

Setup: open a terminal

Nothing to solve here. This is what success looks like.

On Linux/macOS the prompt shows your user, your computer and your current folder (~ = home):

user@gnugen:~ $

On Windows (Git Bash) the same information, different dress:

user@DESKTOP-123 MINGW64 ~
$

You type commands after the $ (or after the prompt line in Git Bash) and press Enter.

The terminal is a file explorer

๐Ÿ‘€ Solution 1 - Click here to reveal

Find out where you are:

pwd
/home/user

On Git Bash the same folder, UNIX spelling:

/c/Users/user

Your home folder: Linux keeps it under /home/you, macOS under /Users/you, Git Bash under /c/Users/you. The same folder that Windows calls C:\Users\you.

๐Ÿ‘€ Solution 2 - Click here to reveal
ls
Desktop  Documents  Downloads  Music  Pictures  Videos

Your list will look different, it is your home folder! In Git Bash, folders are often displayed with a trailing / (e.g. Documents/).

Answer: the same folders and files as in the file explorer. Two windows, one disk.

๐Ÿ‘€ Solution 3 - Click here to reveal
ls -a
.  ..  .bash_history  .profile  Desktop  Documents  Downloads  Music  Pictures  Videos
  • . is a shortcut for this folder, .. for the parent folder
  • files starting with a dot (like .bash_history) are hidden by default, they are configuration files
  • the exact hidden files you see depend on your system (on Windows you may also spot some hidden system files)

Answer: hidden files appeared, their names start with a dot. In the file explorer they only show once you enable show hidden files. The files were always there.

Commands are programs

๐Ÿ‘€ Solution 1 - Click here to reveal
whoami
user

On Git Bash you may get DESKTOP-123\user, your username prefixed with the computerโ€™s name.

date
Sun Oct  4 21:00:00 CEST 2026

The exact format depends on your language/region settings.

git --version
git version 2.47.1.windows.1

(On Linux/macOS: git version 2.47.1. The .windows.1 suffix only appears on Windows.)

Answer: whoami prints your username, date prints date and time. git --version asks the git program for its version. All three are programs, the terminal just launched them.

๐Ÿ‘€ Solution 2 - Click here to reveal
explorer .

(Windows / Git Bash) No text is printed, a File Explorer window opens at your current location.

On Linux / macOS:

xdg-open .
open .

Answer: the File Explorer opened exactly where your terminal is. You launched the file explorer program by typing its name, the same program that starts when you click its icon.

๐Ÿ‘€ Solution 3 - Click here to reveal

On Linux (if Firefox is installed):

firefox

Firefox opens, as if you had clicked its icon. The terminal waits while Firefox runs. Close it (or press ctrl + c) to get your prompt back.

On Windows (Git Bash):

notepad

Answer: Notepad opens, exactly like clicking its icon. It lives in C:\Windows\System32, a folder on the PATH. bash searches those folders and starts the program by itself.

On macOS:

open -a Safari

Answer: Safari opens. macOS apps are not on the PATH. open hands the name to macOS, which knows its own apps.

This only works for programs on the PATH. The same rule on every system. If a plain name fails with command not found, that program is not on the PATH, like firefox on many Git Bash machines.

Moving around

๐Ÿ‘€ Solution 1 and 2 - Click here to reveal

Enter a folder (relative path, from where you are):

cd Documents
pwd
/home/user/Documents

Answer: /home/user/Documents, the same folder you double-clicked into in the file explorer.

Go back up (.. is the parent folder):

cd ..
pwd
/home/user

Answer: back home, exactly like clicking the up button in the file explorer.

๐Ÿ‘€ Solution 3 - Click here to reveal

Three ways to get home:

cd ~
cd

cd with no argument goes home by default.

cd /home/user

Absolute path, starts at the root /, works from anywhere. On Git Bash:

cd /c/Users/user

Answer: yes, all three end at your home folder. Check with pwd.

๐Ÿ‘€ Solution 4 (bonus) - Click here to reveal
cd Documents
cd -
/home/user

Answer: cd - takes you to the folder you came from, like the back button. Running it again toggles between the two folders.

Create a folder and edit a file

๐Ÿ‘€ Solution 1, 2 and 3 - Click here to reveal

Create the playground folder:

mkdir gnugen-shell-workshop
ls
Desktop  Documents  Downloads  gnugen-shell-workshop  Music  Pictures  Videos

Answer: yes, the folder appears in the terminal and in the file explorer (same disk). Press F5 to refresh if needed.

Step inside and create an empty file:

cd gnugen-shell-workshop
pwd
/home/user/gnugen-shell-workshop

Answer: pwd prints the new folder, you are really inside.

touch notes.txt
ls
notes.txt

Answer: an empty notes.txt appeared in both windows.

touch creates an empty file. If it already exists, touch does nothing harmful. One of the safe ones.

๐Ÿ‘€ Solution 4 and 5 - Click here to reveal

Edit with nano:

nano notes.txt
  • type your lines, e.g. I can edit files in the terminal!
  • ctrl + o saves (nano asks File Name to Write: notes.txt, Enter confirms). โš ๏ธ Saving overwrites the file with what you see on screen. That is exactly what you want while editing
  • ctrl + x exits
  • the shortcuts are always shown at the bottom, ^ means ctrl

Answer: the file is no longer empty, your text is in it.

Verify by double-clicking notes.txt in the file explorer, or print it in the terminal:

cat notes.txt
I can edit files in the terminal!

Answer: same text in both windows. It is the same file, no copy was made.

Copy, rename and move

๐Ÿ‘€ Solution 1 and 2 - Click here to reveal

Copy (โš ๏ธ cp would silently overwrite backup-of-notes.txt if it already existed):

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

Answer: ls shows two files with the same content. Check the file explorer, both are there.

Rename the copy with mv (โš ๏ธ same overwrite rule):

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

Answer: backup-of-notes.txt is gone, it is now called my-backup.txt. mv is also the terminalโ€™s rename: moving a file to a new name.

๐Ÿ‘€ Solution 3 - Click here to reveal

Create a subfolder and move the file into it, the terminalโ€™s drag & drop:

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

Answer: my-backup.txt sits inside archive now, in both windows.

Pipes and redirection

๐Ÿ‘€ Solution 1, 2 and 3 - Click here to reveal
echo "hello from the shell!"
hello from the shell!

Answer: echo prints text to the screen.

Send it into a file with > (โš ๏ธ > overwrites the target file without asking):

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

Answer: message.txt contains the line you sent into it. Check the file explorer, it is there too.

Append a second line with >>. Two arrows add, one arrow replaces:

echo "one more line" >> message.txt
cat message.txt
hello from the shell!
one more line

Answer: the second cat shows both lines. >> appended, > would have replaced.

๐Ÿ‘€ Solution 4 - Click here to reveal
ls | wc -l
3

At this point the playground folder contains archive, message.txt and notes.txt, so 3. Your number may differ.

Answer: the number you counted in the file explorer. ls lists the files, wc -l counts the lines it receives. The file explorer shows the same count as x items in its status bar.

Variables

๐Ÿ‘€ Solution 1 and 2 - Click here to reveal

Set a variable and read it back (no spaces around =!):

name="ado"
echo $name
ado

Answer: ado appears. The shell replaces $name with the value before echo runs, echo just prints what it receives.

Change the value:

name="gnugen"
echo $name
gnugen

Answer: gnugen. Same mechanism, new value: the variable holds whatever you last stored in it.

๐Ÿ‘€ Solution 3 and 4 - Click here to reveal

HOME is an environment variable, shared with every program you launch:

echo $HOME
/home/user

On Git Bash:

/c/Users/user

Answer: your home folder. It is the long form of ~: ~ is just the shellโ€™s abbreviation for $HOME.

See all environment variables:

env
HOME=/home/user
SHELL=/bin/bash
TERM=xterm-256color
USER=user
[...]

Answer: yes, USER=user (on Windows: USERNAME=user). On Git Bash the list is much longer and contains Windows variables as well (USERPROFILE, โ€ฆ). Git Bash is a guest in Windowsโ€™ house, env shows what it carries with it.

Errors and return codes

๐Ÿ‘€ Solution 1 and 2 - Click here to reveal

Read a file that does not exist. Nothing can break, reading a missing file only fails:

cat doesnotexist.txt
cat: doesnotexist.txt: No such file or directory

Answer: an error message, and nothing else happened. The file explorer shows no change, there was nothing to change.

Ask for the return code:

echo $?
1

Answer: 1, a non-zero number = error. ($? always refers to the last command you ran.)

๐Ÿ‘€ Solution 3 and 4 - Click here to reveal

A typo is not a program. The shell itself complains:

lss
bash: lss: command not found
echo $?
127

Answer: 127, the shellโ€™s code for program not found.

For contrast, success is silence and 0:

cat message.txt
echo $?
hello from the shell!
one more line
0

Answer: 0. So: 0 = success, anything else = error. (And explorer . on Windows always returns 1, even on success. Programs may break the convention, well-behaved UNIX programs follow it.)

Getting help

๐Ÿ‘€ Solution 1 - Click here to reveal

(Linux and macOS, Git Bash has no man, see the next solution)

man ls
LS(1)                           User Commands                          LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...
[...]

A full-screen page opens with the programโ€™s name, description and all options. Scroll with the arrow keys or page keys, quit with q.

(If you got bash: man: command not found, you are in Git Bash. Use --help instead.)

๐Ÿ‘€ Solution 2 and 3 - Click here to reveal
ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
[...]
  -a, --all                  do not ignore entries starting with .
[...]

Answer: the option is -a, long form --all. The help spells out the long name: many flags have a short and a long form.

On macOS, ls ignores --help. That is what man ls is there for.

And man man? Answer: the manual of the manual, documentation about the documentation program. The shell has a sense of humor too. ๐Ÿ˜‰

Bonus: permissions

๐Ÿ‘€ Solution 1 and 2 - Click here to reveal
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 1 user user  0 Oct  4 20:58 archive

(In Git Bash you may see a number instead of the group name and different spacing, that is fine.)

How to read a line like -rw-r--r--:

  • character 1: - file, d directory
  • characters 2 to 10, three groups of three: r = read, w = write, x = execute, for the owner, the group, everyone else
  • -rw-r--r--: owner may read and write, group and others may only read
  • drwxr-xr-x: a directory the owner can enter (x on a directory means enter it)

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

The round trip

๐Ÿ‘€ Solution 1 and 2 - Click here to reveal

Terminal โ†’ file explorer: from your playground folder:

pwd
/home/user/gnugen-shell-workshop
explorer .

(Linux: xdg-open ., macOS: open .)

Answer: the file explorer opened in the exact folder pwd just printed.

File explorer โ†’ terminal: right-click on empty space inside the folder:

  • Windows: Git Bash Here (Windows 11: Show more options first)
  • Linux: Open in Terminal (name depends on your file manager)
  • macOS: no right-click entry. Drag the folder onto a Terminal window, or use open . from the terminal side

The new terminal starts in this folder. Check with pwd. Both windows, same path, in both directions.

Cleanup

๐Ÿ‘€ Solution - Click here to reveal

There is no terminal command today, on purpose! Deleting in the shell happens without a trash bin and without undo, so the safe way for now is:

  1. in the file explorer, right-click the gnugen-shell-workshop folder
  2. choose Move to trash / Delete
  3. (empty the trash if you want it really gone)

One folder less. Same result as in the file explorer, which is the whole point of this workshop.

Common issues

symptom likely cause what to do
bash: xyz: command not found typo, or the program is not on the PATH check spelling. Not every program is on the PATH
No such file or directory typo in a name, or you are in a different folder than you think pwd and ls to orient yourself, cd ~ to get home
Permission denied you may not touch that file stay inside your own folders, the exercises never need admin rights
the prompt is gone / the terminal ignores you a program is still running press ctrl + c to stop it
terminal full of old output nothing wrong clear wipes the screen
nano refuses to quit you have unsaved changes ctrl + o, Enter to save, then ctrl + x
explorer . โ€œfailedโ€ it didnโ€™t, it always reports code 1 if the window opened, everything is fine