Intro to Git — Snapshots, Branches & Sharing
WorkshopyOfficial10 stepsQuiz9 interactiveDiagram
gitversion controlbeginners
Linux command line exercises for beginners: practise cd, ls, cp, mv, rm, grep and pipes in a browser terminal that checks each task.

WorkshopyOfficial
40 lessons · used by 2 teachers
Sign in to copy it to your workspace. It’s free.
11 steps · 2 quizzes · open any step, or read it here
In this lesson you practise the Linux command line with exercises you do in a terminal that runs in your browser. You move between folders, create, copy, move and delete files, read and search a log file, and join commands with pipes, and a file tree beside the terminal shows what every command changed.
Watch five commands run, then type your own:
Interactive · A practice terminal with a live file tree — try it in the lesson
In this lesson you'll:
pwd, ls, cd)cat, head, tail, wc, grep)|, and save the result with >It takes about an hour. Each step has a terminal with a short list of tasks; they tick themselves when the files look right. Nothing you type can harm a real computer: the files are pretend, and Start again puts them back.
Takeaway: a command is a word, then options and names, then Enter.
The command line always works in one folder at a time, the working directory. Two commands tell you about it:
pwd (print working directory) prints the full path of the folder you are in.ls (list) shows what is in it. Folders are shown in blue.ls takes options, letters after a dash that change what it does, and names:
| Command | What it shows |
|---|---|
ls |
the names in this folder |
ls -a |
also the hidden files, whose names start with a dot (.bashrc) |
ls -l |
one line per item: type and permissions, owner, size in bytes, date, name |
ls reports |
what is inside the folder reports, without going there |
Options can be joined: ls -la is ls -l -a.
Try it: do the five tasks. The prompt dana@demo:~$ says who you are (dana), which computer (demo) and where you are: ~ is short for your home folder, /home/dana.
Interactive · pwd and ls in a practice terminal — try it in the lesson
In the ls -l lines, the first letter is d for a folder and - for a file. What is the size of notes.txt in bytes?
Takeaway: pwd says where you are; ls says what is there.
A path names a file or folder by the folders you pass on the way to it. There are two kinds:
/, at the top of everything: /home/dana/projects/website. It means the same thing wherever you are./home/dana/reports, the website folder is ../projects/website.Two short names make relative paths work. . is the folder you are in, and .. is the folder above it. Each .. climbs one level; then you walk down by naming folders, joined by /. And ~ is your home folder, wherever you are.
Try it: tap folders in the tree to see the route between where you are and where you want to go. Then switch to Tap sets: where you are and move yourself.
Interactive · Absolute and relative paths, drawn as a route — try it in the lesson
Pick /tmp as where you go. Why is the absolute path shorter than the relative one from reports?
Takeaway: absolute paths start with /; relative paths start from where you are, and .. climbs one level.
cd (change directory) moves you to another folder. It prints nothing when it works; the prompt and pwd show where you landed.
| Command | Where it takes you |
|---|---|
cd reports |
into reports, inside the folder you are in |
cd .. |
up one level |
cd ../.. |
up two levels |
cd /tmp |
to /tmp, by its absolute path |
cd or cd ~ |
home, to /home/dana |
cd - |
back to the folder you were in before |
Press Tab while typing a name and the terminal completes it, which saves typing and spelling mistakes. Press ↑ to bring back the last command.
Try it: do the tasks, and watch the you are here mark move in the tree.
Interactive · cd in a practice terminal — try it in the lesson
Check your work · Go into `projects/website`. Then run `cd ../..` and `pwd`. Paste what `pwd` printed. — check it in the lesson
Takeaway: cd moves you, cd .. climbs, cd alone goes home.
mkdir archive makes a folder named archive.mkdir archive/2026 makes 2026 inside archive, but only if archive already exists. If it doesn't, you get No such file or directory.mkdir -p archive/2025/q4 makes every missing folder on the way (the -p is for parents), and says nothing if they already exist.mkdir jan feb mar makes three folders at once: most commands take several names.touch readme.txt makes an empty file (if the file exists, it only updates its date).Names with spaces are trouble on the command line, because a space separates names: mkdir my files makes two folders, my and files. Use - or _ instead, or put the name in quotes: mkdir "my files".
Try it: build the archive in the tasks. Each new folder lights up in the tree.
Interactive · mkdir and touch in a practice terminal — try it in the lesson
What happens if you run mkdir archive a second time?
Takeaway: mkdir makes folders, -p makes the whole path, touch makes an empty file.
Four questions on the first half.
Question 1. You type pwd and see /home/dana/reports. Where are you after cd ..?
Question 2. Which of these is an absolute path?
Question 3. mkdir archive/2026 fails with "No such file or directory". Why?
Question 4. Which command also lists hidden files such as .bashrc?
cp notes.txt reports/ copies notes.txt into reports. The original stays.cp notes.txt notes-copy.txt makes a copy with a new name.cp -r projects/website website-backup copies a folder and everything in it. Without -r (recursive), cp skips folders.mv q1-sales.csv reports/old/ moves a file into another folder.mv todo.txt tasks.txt renames: on the command line, renaming is moving to a new name in the same folder.The rule for both: the last name is the destination. If it is a folder that exists, the item goes inside it, keeping its name; otherwise the item takes the last name as its new name.
Careful: if the destination is a file that already exists, cp and mv replace it without asking. Add -i in a real terminal and they ask first.
Try it: do the tasks, and watch where each file appears in the tree.
Interactive · cp and mv in a practice terminal — try it in the lesson
After cp notes.txt reports/, change nothing and run cat reports/notes.txt. Is it the same text as notes.txt?
Takeaway: cp copies (-r for folders), mv moves and renames, and the last name is the destination.
rm junk.txt deletes a file.rmdir empty-folder deletes a folder, but only an empty one.rm -r old deletes a folder and everything inside it.rm reports/*.csv deletes every file in reports whose name ends in .csv. The * matches any characters; the shell replaces reports/*.csv with the matching names before rm runs.There is no recycle bin on the command line. A file deleted with rm is gone; nothing asks you to confirm. Two habits keep you safe:
ls with the same name first: ls reports/*.csv shows exactly what rm reports/*.csv would delete.rm -rf with a name you haven't checked. -f (force) hides every warning.Try it: clean up the home folder.
Interactive · rm and rmdir in a practice terminal — try it in the lesson
Before the last task, run ls reports/*.csv. Which files does the * match?
Takeaway: rm deletes for good; check the names with ls first.
cat notes.txt prints the whole file.head -n 3 reports/q1-sales.csv prints its first 3 lines; head alone prints 10.tail -n 2 logs/app.log prints the last 2 lines. Logs grow at the end, so tail shows what happened last.wc -l logs/app.log counts its lines (wc is word count: alone it prints lines, words and bytes).For a long file in a real terminal, less app.log shows one screen at a time (Space for the next page, q to quit).
Try it: read the files in the tasks. The log has one line per event, with its time and its level: INFO, WARN or ERROR.
Interactive · cat, head, tail and wc in a practice terminal — try it in the lesson
Check your work · How many sales rows are in `reports/q1-sales.csv`, not counting the header line (`region,rep,amount`)? Count the lines with `wc -l`, then paste your answer. — check it in the lesson
Takeaway: cat shows all, head the start, tail the end, wc -l counts lines.
grep prints the lines of a file that contain a pattern. It is how you find the five lines that matter in a log of five thousand.
| Command | What it prints |
|---|---|
grep ERROR logs/app.log |
every line that contains ERROR |
grep -c ERROR logs/app.log |
how many lines contain it |
grep -v INFO logs/app.log |
every line that does not contain INFO |
grep -i anna logs/app.log |
matches whatever the capitals: anna, Anna, ANNA |
grep -n ERROR logs/app.log |
the matching lines with their line numbers |
grep "payment failed" logs/app.log |
lines with the two words together, in quotes because of the space |
grep is case-sensitive: without -i, grep error finds nothing in this log, where every level is in capitals.
Try it: investigate the log.
Interactive · grep in a practice terminal — try it in the lesson
Check your work · Run `grep -c ERROR logs/app.log` and paste what it printed. — check it in the lesson
Takeaway: grep finds lines; -c counts, -v inverts, -i ignores capitals.
Each command reads text and writes text. The pipe, |, sends what one command prints into the next command instead of to the screen:
grep ERROR logs/app.log | wc -l counts the ERROR lines: grep finds them, wc counts them.sort logs/tickets.txt | uniq -c | sort -rn lists the support ticket topics, most common first.uniq removes repeated lines, but only lines that sit next to each other, which is why sort comes first. uniq -c puts the count in front of each line, and sort -rn sorts by that number (-n), largest first (-r).
Try it: switch commands on and off and watch the lines flow through the pipe. Turn off the first sort: what happens to the counts?
Interactive · Lines flowing through a pipe — try it in the lesson
Redirection sends what a command prints into a file:
grep ERROR logs/app.log > errors.txt writes the lines to errors.txt. > creates the file, or replaces what was in it.grep WARN logs/app.log >> errors.txt adds the lines to the end of the file.Try it: do the tasks.
Interactive · Pipes and redirection in a practice terminal — try it in the lesson
Check your work · Run `sort logs/tickets.txt | uniq -c | sort -rn` and paste the four lines it printed. — check it in the lesson
Takeaway: | passes output to the next command, > saves it to a file, >> adds to one.
Answer each exercise, then check. A hint costs nothing, and a wrong answer costs nothing either.
Six questions on the whole lesson.
Question 1. What is the difference between > and >>?
Question 2. Which command copies the folder website and everything in it to website-backup?
Question 3. Why do you sort a file before uniq -c?
Question 4. What does tail -n 5 logs/app.log show?
Question 5. Which of these commands change files or folders? (pick all)
Question 6. You ran rm report.txt by mistake. Where is the file now?
Workshopy shares this lesson under CC BY 4.0. Anyone may use and change it, with credit to you. Anyone can learn it here, free. A copy in your workspace is yours to change and run live; your students never need an account.
Version 3Current
· All practice terminals now run commands on Enter and Run.
Version 2
· The practice terminals now run commands on Enter and Run.
Version 1
· First published
Copies are made from the current version. A copy you already have doesn’t change.
WorkshopyOfficial10 stepsQuiz9 interactiveDiagram
gitversion controlbeginners
WorkshopyOfficial16 steps2 quizzes15 interactiveDiagram
workshopyproduct touronboarding
WorkshopyOfficial11 steps2 quizzes10 interactive
gitmerge conflictsbranching
WorkshopyOfficial11 steps2 quizzes10 interactive
recursionprogrammingpython
WorkshopyOfficial11 steps2 quizzes10 interactive
graphsalgorithmsdijkstra
WorkshopyOfficial11 steps2 quizzes12 interactive
binarycomputer sciencebits and bytes
Comments
No comments yet. Be the first to say how it went.