Lab: Shell basics practice
Consolidate your Bash knowledge with a quiz covering navigation, files, variables, scripts, and pipelines.
- Recall the key commands and concepts from across the Shell basics module
- Predict the output of shell commands and pipelines before running them
- Apply commands to solve realistic file and script tasks
This is an optional lab. No new concepts — just a chance to consolidate what you've learned across the Shell basics module. Work through each quiz section, then try the "Do it yourself" challenges in your own terminal.
The shell rewards hands-on practice more than almost any other tool. This lab is designed to make you predict what commands will do before you run them — and then verify by actually running them. That feedback loop is how beginners become fluent.
Section 1 — Navigation and filesystem
Knowledge check
- 1.You are in /home/alice/projects. Which command takes you directly to /home/alice?
- 2.Which command shows ALL files in the current directory, including hidden ones, with detailed metadata?
- 3.cd - takes you back to the directory you were in before the last cd.
Section 2 — Files and directories
Knowledge check
- 1.You want to create the nested path projects/web/src in one command. Which works?
- 2.Which command correctly deletes the directory my-project and all its contents?
- 3.mv can rename a file and move it to a different directory in a single command.
Section 3 — Variables and environment
Knowledge check
- 1.Which assignment is syntactically correct in Bash?
- 2.Given msg="world", what does echo 'hello $msg' print?
- 3.Which statements about $PATH are true?
Section 4 — Scripts and permissions
Knowledge check
- 1.A script file starts with #!/bin/bash. What is the purpose of this line?
- 2.A script is run as ./deploy.sh production v1.5. What is the value of $1?
- 3.chmod +x script.sh grants execute permission to the file's owner, group, and others.
Section 5 — Pipes and redirects
Knowledge check
- 1.What does ls /usr/bin | wc -l do?
- 2.You want to add a new line to log.txt without deleting its existing content. Which operator do you use?
- 3.You run ls /fakepath > output.txt. Where does the error message appear?
Do it yourself challenges
These challenges require a real terminal. Work through each one — the goal is to practice without looking things up.
Challenge 1: Directory explorer
Without using your file manager, find and list the contents of three different directories on your system. Use only cd, ls, pwd, and tab completion. Navigate back to your home directory at the end using a single command.
# Start here and explore:
cd /
ls
# ... keep going
cd ~Challenge 2: File pipeline
Create a file with at least ten fruit names (one per line), then use a pipeline to:
- Count how many there are
- Show only names starting with the letter "a" or "A"
- Sort them alphabetically
# Create the file — add your own fruits
echo "apple" > fruits.txt
echo "banana" >> fruits.txt
# ... add more
# Then build the pipelines
wc -l fruits.txt
grep -i "^a" fruits.txt | sortChallenge 3: Your first real script
Write a script called info.sh that prints:
- Your username
- Your current directory
- The number of files in the current directory
- Today's date
touch info.sh
chmod +x info.sh
# edit the file, then run:
./info.shHints: whoami, pwd, ls | wc -l, and date are all commands you've seen. Put them together with echo for labels.
Challenge 4: Safe cleanup script
Write a script clean-tmp.sh that:
- Accepts a directory name as
$1 - Checks if an argument was provided (hint:
[ -z "$1" ]tests for an empty string) - If no argument: prints a usage message and exits
- If an argument was provided: lists the directory contents before deleting them
This is a realistic safety pattern — always show what you're about to delete before deleting it.
When the agent's away
Now that you know the Shell basics, the most productive thing you can do is use the shell for real tasks you'd normally do through a file manager or IDE:
- Navigate your projects with
cdandlsinstead of clicking - Use
grep -r "TODO" .to find outstanding work across your codebase - Write a small script to automate something repetitive you do every week
- Pipe
git log --oneline | head -10to see recent commit history
Every tool you learn this way stays with you — and when an AI agent builds a pipeline in front of you, you'll understand exactly what it's doing.
Where to go next
You've completed the Bash Shell basics module. You can navigate filesystems, manage files, work with variables, write executable scripts, and compose powerful pipelines. The next step is the intermediate track — conditionals and loops, functions in shell scripts, string manipulation, and working with processes and signals.