mkdir -p

Definition

mkdir -p is a command-line instruction used on Unix-like systems to create a directory and any necessary parent directories in one step. The -p option stands for "parents" and also prevents an error if the target directory already exists.

Why it matters

Creating directories is a fundamental file-system operation when organising projects, preparing build or deployment folders, or scripting automation. The -p option makes directory creation idempotent and robust: it builds entire directory trees in a single call and avoids failures when a directory is already present, which simplifies scripts and reduces error handling.

Example in VCA

mkdir -p ~/vibe-projects/env-test

This creates the folder env-test inside vibe-projects in your home directory, creating vibe-projects first if it doesn't exist. Using -p means you can run the command multiple times without an error if the directories already exist.

Another Real World Example

mkdir -p /var/www/myapp/releases/2026-03-16

Useful during deployments to create a nested release directory in one command. If parts of the path are missing, mkdir -p will create them so the deployment script can proceed without extra checks.

Common mistakes

  • Expecting the exact same flag behaviour in all shells: -p is standard on POSIX shells (Linux, macOS). Windows shell behaviour differs; use the appropriate PowerShell commands when on Windows.
  • Forgetting to quote paths with spaces, e.g. mkdir -p "My Projects/Name" is required on paths containing spaces.
  • Confusing files and directories: if a file exists with the same name as the final directory, mkdir -p will fail.
  • Assuming permissions will be created as you expect: parent directories are created with default permissions influenced by the current umask; you may need to adjust permissions afterwards with chmod or chown.
  • Using relative vs absolute paths unintentionally: mkdir -p docs/api will create directories relative to the current working directory.

Related terms

  • mkdir
  • rmdir
  • rm -r
  • touch
  • cd
  • absolute path
  • relative path
  • shell
  • home directory
  • chmod

Cookie choices

We use cookies to improve your experience

We use essential cookies to keep the platform working, and optional analytics to improve it.