None of the directories in logs/2026/08 exist.
Create the full path with one mkdir command.
Which command is appropriate?
mkdir -p creates missing parent directories before the final directory and tolerates already existing directories.
Detailed explanation
mkdir logs/2026/08Incorrect. Without -p, mkdir fails when parent directories are missing.
mkdir -p logs/2026/08Correct. mkdir -p logs/2026/08 creates every missing level.
mkdir -m logs/2026/08Incorrect. -m sets a mode and does not replace the need for -p.
rmdir -p logs/2026/08Incorrect. rmdir removes directories rather than creating them.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir -p "$tmp/logs/2026/08"; test -d "$tmp/logs/2026/08" && echo created; rm -rf "$tmp"Expected result
createdKey points
- -p means parents
- Create missing parents
- Existing directories are allowed
Notes
- Environment: GNU coreutils 9.x / 一時ディレクトリ
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
The parents option turns a multi-level path creation into one operation and avoids an error for existing parents.
Check the side effect
Run the command twice in a temporary directory to observe its repeatable behavior.