Nested Directories & Options
Concept & Overview
Imagine trying to build a set of nesting dolls, but you have to build the outermost ones before you can build the tiny one inside. By default, mkdir is like that—it refuses to create a folder deep inside folders that don't exist yet. To skip the hassle of creating folders one-by-one, we use a switch:
- The -p (or --parents) option tells mkdir to automatically build any missing parent folders on its way to the final folder. For example, mkdir -p workspace/src/utils creates workspace, workspace/src, and workspace/src/utils all in a single command.
Why this matters: If you run mkdir workspace/src/utils without -p, and workspace and workspace/src don't already exist, you'll get: mkdir: cannot create directory 'workspace/src/utils': No such file or directory. The -p flag fixes this by creating all missing parent folders automatically.
workspace/src/utils in your home folder using mkdir -p workspace/src/utils.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
mkdir -p path | Create nested directories and parent directories |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Create nested directory workspace/src/utils
- ○Use the -p or --parents switch in mkdir
Ready to complete Quest 5?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.