Learn Everything

Paths/DevOps Engineer/Linux / Shell Scripting Basics

Guided Taskbeginnerubuntu:24.04Ask AI

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

⏱ 0:00

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
  1. 01

    Create the scripts directory

    Keep your scripts together, away from the data they touch.

    mkdir ~/scripts
  2. 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
  3. 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
  4. 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
  5. 05

    Verify the script

    ls -l shows the mode column: -rwx------ means owner only, with the executable bit set.

    ls -l ~/scripts
  6. 06

    Submit for validation

    The validator checks the shebang, the tar call and the mode.

03Stuck?

0 of 3 revealed

Take a hint without losing the lab — each one points at the thing to look at, not at the answer.

04AI Tutor

guides, never solves

Tell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?

04Notebook

saved locally in this browser

learner@lab — ubuntu:24.04

↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list