Overview
Workshop
This workshop is the hands-on follow-up to our just do git — shell presentation.
Two ideas to take home:
- The file explorer and the terminal show the same files. They are just two windows into your computer.
- 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 --helpfor a short summary,man CMDfor the full manual (nomanin Git Bash).
Setup: open a terminal
-
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. -
The prompt is the line where you type:
user@gnugen:~ $In Git Bash it looks like this:
user@DESKTOP-123 MINGW64 ~ $useris 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\youappears as/c/Users/youin 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.
- 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
-
List the files in this folder:
lsQuestion: Compare the output with the file explorer. What do you see?
-
Also show the hidden files (their names start with a dot, like
.gitconfig):ls -aQuestion: 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 + hin 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.
-
Run these three programs (one at a time):
whoami date git --versionQuestion: Before running: what will
whoamiprint? Anddate? Guess first.(
gitis a version control program, you will meet it in one of our other workshops. If it is not installed on your Linux, you getcommand not found, that is fine too.) -
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?
-
The same trick works for any program. On Linux, if Firefox is installed:
firefoxOn Windows (Git Bash), try the same with Notepad:
notepadOn macOS, launch Safari like this:
open -a SafariOnly programs on the
PATHstart 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
-
Enter your
Documentsfolder and check where you are:cd Documents pwdQuestion: Before
pwd: which folder do you expect? -
Go back up and confirm:
cd .. pwdQuestion: Where are you now?
-
Three ways to get home. Do they all end in the same place?
cd ~cdcd /home/user(the last one is an absolute path; Git Bash:
cd /c/Users/user) -
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
Tabwhile typing a name and the shell completes it.cd Doc+Tabbecomescd 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.
-
Create a new folder (no spaces in the name, they make shell life harder):
mkdir gnugen-shell-workshopQuestion: Will the folder also appear in the file explorer? Guess, then check (press
F5to refresh). -
Step into it and check you are really inside:
cd gnugen-shell-workshop pwdQuestion: What will
pwdprint? -
Create an empty file:
touch notes.txtQuestion: Check the file explorer. What changed?
-
Now write something in it, inside the terminal, with the
nanoeditor:nano notes.txt- type a few lines, e.g.
I can edit files in the terminal! - the shortcuts are always shown at the bottom;
^meansctrl
- type a few lines, e.g.
-
Verify in the file explorer, double-click
notes.txtand make sure your text is there!
Copy, rename and move
⚠️ Warning:
cpandmvoverwrite an existing destination file silently, without asking! If the destination name already exists, it is replaced. Always double-check your file names!
-
Make a copy of your notes (the terminal way to copy & paste):
cp notes.txt backup-of-notes.txt lsQuestion: How many files will
lsshow? Guess before running. -
Rename the copy (renaming is moving a file to a new name):
mv backup-of-notes.txt my-backup.txt lsQuestion: Where did
backup-of-notes.txtgo? -
Create a subfolder and move the file into it (the terminal way to drag & drop):
mkdir archive mv my-backup.txt archive/ ls ls archiveQuestion: Check the file explorer. Where is
my-backup.txtnow?
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
rmcommand.
Pipes and redirection
Two small superpowers of the shell.
-
echo:echo "hello from the shell!"Question: Before running: what do you think
echodoes? -
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.txtQuestion: What is in
message.txtafterwards? -
>>appends at the end instead of overwriting:echo "one more line" >> message.txt cat message.txtQuestion: How does the output differ from the last
cat? -
The pipe
|chains programs: the output of the first becomes the input of the second:ls | wc -lQuestion: Count the files in this folder in the file explorer first (it shows its count as “x items”). What will
ls | wc -lprint? Run and compare.
Variables
-
A variable stores a value in your current session (no spaces around the
=!):name="ado" echo $nameQuestion: Before you execute
echo $name: what do you think will appear? What appears after executing? -
Change the value and repeat:
name="gnugen" echo $nameQuestion: And now?
-
Environment variables are shared with every program you launch. One you will meet everywhere is
HOME, your home folder:echo $HOMEQuestion: What do you expect? How does it relate to
~? -
See all of them:
envQuestion: 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?
-
Try to read a file that does not exist (don’t worry, reading a missing file breaks nothing):
cat doesnotexist.txtQuestion: What do you think happens?
-
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. -
Try a typo:
lssecho $?Question: Before running: what do you think
echo $?will show? -
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:
-
The manual,
man(Linux and macOS):man lsA 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 getcommand not found. Use the next trick there. -
The quick help (Linux and Git Bash):
ls --helpMost 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. Usemanthere. -
Bonus round: what do you think
man manshows? 😉
💡 Tip:
qquits any full-screen terminal program (man,less, …).
Bonus: permissions
Files carry permissions: who may read, write, or execute them.
-
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)
-
How to read it:
- first character:
-file,ddirectory - 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).
- first character:
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! :))