Navigation and files

Command mkdir

Create directory

Linux · Bash examples · commands run on the selected server

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

-p
Create missing parent directories.
-m MODE
Set the permissions of the created directory.
-v
Show created directories.

Usage examples

Create directory

mkdir ./reports

A single directory is created; an existing directory normally causes an error.

Create a nested structure

mkdir -p ./project/logs

Missing parent directories are created, and an already existing directory is accepted.

Create a private directory

mkdir -m 700 ./private

The 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.