Create var/cache/app below the current directory.
Create var and var/cache in the same command if they do not exist.
Which command is appropriate?
mkdir -p creates missing parent directories in the requested path and accepts parents that already exist.
Detailed explanation
mkdir var/cache/appIncorrect. Without -p, mkdir fails when a parent directory is missing.
Incorrect. Without -p, mkdir fails when a parent directory is missing.
rmdir -p var/cache/appIncorrect. rmdir removes directories rather than creating them.
Incorrect. rmdir removes directories rather than creating them.
touch var/cache/appIncorrect. touch creates files and cannot create a directory hierarchy.
Incorrect. touch creates files and cannot create a directory hierarchy.
mkdir -p var/cache/appCorrect. mkdir -p creates all missing levels in the path.
Correct. mkdir -p creates all missing levels in the path.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
mkdir -p "$LAB_DIR/var/cache/app"
test -d "$LAB_DIR/var/cache/app" && echo CREATED
rm -r "$LAB_DIR"Expected result
CREATEDKey points
- -p creates missing parents
- One command creates the hierarchy
- Existing parents are allowed
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.