Paths/DevOps Engineer/Linux / Shell Scripting Basics
Write a Backup Script
A backup you have to remember to run is a backup you do not have. Write a script that archives the project directory and can only be run by its owner.
Validator
IDLE — checks run live as you type commands; submit when done
01Requirements
live checks- Directory ~/scripts exists○
- File ~/scripts/backup.sh exists and starts with a shebang○
- The script archives with tar○
- Permissions on ~/scripts/backup.sh are 700 (owner only, executable)○
02Walkthrough
6 steps- 01
Create the scripts directory
Keep your scripts together, away from the data they touch.
mkdir ~/scripts - 02
Write the shebang
#!/bin/bash tells the kernel which interpreter runs the file. Without it the script is just text.
echo '#!/bin/bash' > ~/scripts/backup.sh - 03
Add the archive command
tar -czf writes a compressed archive: -c creates, -z compresses with gzip, -f names the output file.
echo 'tar -czf ~/backups/project.tar.gz ~/project' >> ~/scripts/backup.sh - 04
Make it owner-only
chmod 700 makes the script executable by its owner and invisible to everyone else - the right mode for anything that touches data.
chmod 700 ~/scripts/backup.sh - 05
Verify the script
ls -l shows the mode column: -rwx------ means owner only, with the executable bit set.
ls -l ~/scripts - 06
Submit for validation
The validator checks the shebang, the tar call and the mode.
03Stuck?
0 of 3 revealedTake a hint without losing the lab — each one points at the thing to look at, not at the answer.
04AI Tutor
guides, never solvesTell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?
04Notebook
saved locally in this browserlearner@lab — ubuntu:24.04
Session is disposable
↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list