Skip to content
  • Official
  • Beginner
  • English
  • 11 steps · 2 quizzes

Linux Command Line Exercises for Beginners

Linux command line exercises for beginners: practise cd, ls, cp, mv, rm, grep and pipes in a browser terminal that checks each task.

  • Free
  • No account needed
  • Stop any time, pick up where you left off
Workshopy.io

WorkshopyOfficial

40 lessons · used by 2 teachers

For teachers

Teaching this? Run it live with your class.

  • Students join with a code — no accounts
  • See who’s done and who’s stuck, step by step
  • It’s your copy — change anything before class

Sign in to copy it to your workspace. It’s free.

Your path

11 steps · 2 quizzes · open any step, or read it here

  1. Linux command line exercises: what you'll practiseStart hereIn this lesson you practise the Linux command line with exercises you do in a terminal that runs in your browser.InteractiveHands-on
    Read this step

    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:

    • find out where you are and what is around you (pwd, ls, cd)
    • make, copy, move, rename and delete files and folders
    • read and search files (cat, head, tail, wc, grep)
    • join commands into one with |, 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.

  2. pwd and ls: where you are and what is hereThe 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.InteractiveHands-on
    Read this step

    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.

  3. Paths: absolute and relativeA path names a file or folder by the folders you pass on the way to it. There are two kinds: An absolute path starts at the root folder, /, at the top of everything: /home/dana/projects/website. It means the same thing wherever you are.InteractiveHands-on
    Read this step

    A path names a file or folder by the folders you pass on the way to it. There are two kinds:

    • An absolute path starts at the root folder, /, at the top of everything: /home/dana/projects/website. It means the same thing wherever you are.
    • A relative path starts from where you are now: from /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.

  4. cd: moving between folderscd (change directory) moves you to another folder. It prints nothing when it works; the prompt and pwd show where you landed.InteractiveHands-on
    Read this step

    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.

  5. mkdir and touch: making folders and filesmkdir 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.InteractiveHands-on
    Read this step
    • 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.

  6. Check: moving around and making foldersFour questions on the first half.Quiz · 4 questions
    Read the questions

    Four questions on the first half.

    Question 1. You type pwd and see /home/dana/reports. Where are you after cd ..?

    • /home/dana
    • /home
    • /home/dana/reports/..
    • Nowhere: cd .. gives an error

    Question 2. Which of these is an absolute path?

    • /home/dana/logs
    • logs/app.log
    • ../reports
    • ./notes.txt

    Question 3. mkdir archive/2026 fails with "No such file or directory". Why?

    • The folder archive doesn't exist yet
    • Folder names can't be numbers
    • mkdir can't make a folder inside another folder
    • Only an administrator can make folders

    Question 4. Which command also lists hidden files such as .bashrc?

    • ls -a
    • ls -l
    • pwd
    • cd ~
  7. cp and mv: copy, move and renamecp 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.InteractiveHands-on
    Read this step
    • 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.

  8. rm and rmdir: deleting for goodrm 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.InteractiveHands-on
    Read this step
    • 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:

    1. Run ls with the same name first: ls reports/*.csv shows exactly what rm reports/*.csv would delete.
    2. Never type 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.

  9. cat, head, tail and wc: reading filescat 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.InteractiveHands-on
    Read this step
    • 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.

  10. grep: finding lines that matchgrep 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.InteractiveHands-on
    Read this step

    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.

Comments

You’ll sign in with Google before it’s posted.Comments are public — don’t name your students.
0 / 1,500

No comments yet. Be the first to say how it went.

Using it

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.

Versions

  1. 3

    Version 3Current

    · All practice terminals now run commands on Enter and Run.

  2. 2

    Version 2

    · The practice terminals now run commands on Enter and Run.

  3. 1

    Version 1

    · First published

Copies are made from the current version. A copy you already have doesn’t change.

More from Workshopy

All 40 lessons
All 8 Programming lessons