Brace Expansion & Safe Directory Removal ({} & rmdir)
Concept & Overview
Bash brace expansion {} is a powerful productivity feature that generates arbitrary string combinations before commands run, eliminating repetitive typing:
- Comma-separated lists: mkdir -p app/{src,bin,logs} expands to app/src, app/bin, and app/logs in a single command.
- Numeric or alphabetic ranges: touch file_{1..3}.txt expands to file_1.txt, file_2.txt, and file_3.txt.
When deleting folders, rm -r deletes everything recursively without safety checks. By contrast, rmdir provides a strict safety guarantee: it only removes directories that are completely empty, preventing accidental loss of files.
1. Run
mkdir -p app/{src,bin,logs} to build multiple application directories at once.2. Run
touch file_{1..3}.txt to create three numbered files in one command.3. Safely delete the empty folder
temp_empty using rmdir temp_empty.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
mkdir -p app/{src,bin,logs} | Create multiple directories using brace expansion |
touch file_{1..3}.txt | Create sequential files using range expansion |
rmdir temp_empty | Safely remove an empty directory |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Create directories app/src, app/bin, and app/logs using brace expansion
- ○Create file_1.txt, file_2.txt, and file_3.txt using brace expansion
- ○Safely remove directory temp_empty using rmdir
Ready to complete Quest 22?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.