When to use mkdir
Use mkdir to prepare directories before writing reports, uploading files or deploying projects. Decide whether missing parent directories should be created and whether the directory needs private access from the start.
Syntax
mkdir [PARAMETERS] DIRECTORY…Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Create directory
mkdir ./reportsA single directory is created; an existing directory normally causes an error.
Create a nested structure
mkdir -p ./project/logsMissing parent directories are created, and an already existing directory is accepted.
Create a private directory
mkdir -m 700 ./privateThe directory is created with access restricted to its owner, subject to filesystem permission semantics.
Notes and limitations
- Without -p, the missing parent directory results in an error.
- The resulting permissions depend on the mode, umask, and file system rules.
Common questions and troubleshooting
Why does mkdir report File exists?
A file or directory already occupies that path. Inspect it first; use -p only when accepting an existing directory is intentional.
Why are permissions different from what I expected?
Without an explicit mode, the process umask restricts the default permissions. ACLs and the filesystem may also affect effective access.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man mkdir.