↑↓ move Enter open Esc close

How to Create Nested Directories in Linux (mkdir -p)

Use mkdir -p to create a directory tree in one command without errors for existing parents.

Plain `mkdir` expects parent directories to exist. For nested paths, `mkdir -p` is the standard solution because it creates every missing component.

Step by step

1 Create one directory

$ mkdir project

Creates a single directory when its parent already exists.

2 Create a complete path

$ mkdir -p project/src/components

Creates project, src and components as needed.

3 Create several directories

$ mkdir -p logs/{app,nginx,archive}

Brace expansion can create several sibling directories in Bash.

4 Verify the result

$ find project -maxdepth 3 -type d

Lists the directory tree so you can confirm the path was created where expected.

Tips worth knowing

Frequently asked questions

What does mkdir -p do?

It creates missing parent directories and does not error if the target directory already exists.

Why does mkdir say No such file or directory?

A parent directory in the requested path does not exist; use `mkdir -p`.

The commands behind it

More how-to guides