mkdir creates directories. Learn how -p builds a whole path at once and how to read a File exists error, by running the commands in a real terminal in your browser.
Updated: 2026-09-04
mkdir [options] directory...
Names separated by spaces are all created.
The terminal on this page starts at the top of a project.
$ ls
README.md src/
$ mkdir tests
$ ls
README.md src/ tests/
mkdir prints nothing on success. Run ls and you can see tests/ has appeared.
| Option | What it does |
|---|---|
-p | Create missing parents too, and do not fail if the directory already exists |
With -p, missing parent directories are created for you.
$ mkdir -p docs/api/v1
$ ls -R docs
docs:
api/
docs/api:
v1/
docs/api/v1:
Neither docs nor docs/api existed, and all three levels appeared in one command.
| Situation | What to type |
|---|---|
| Make one scratch directory | mkdir work |
| Lay out a known structure | mkdir -p src/components src/utils |
| Inside a script | mkdir -p, so a rerun does not stop |
Reach for -p in scripts by default. An existing directory is not an error, so running the same script twice does not halt halfway through.
An existing name is an error.
$ mkdir src
mkdir: cannot create directory 'src': File exists
With -p, this case is treated as success instead.
A missing parent is an error.
$ mkdir a/b
mkdir: cannot create directory 'a/b': No such file or directory
a does not exist, so a/b cannot be created. mkdir -p a/b creates a first.
Success is silent.
Nothing printed means it worked. Run ls when you want to see the result.
Terminal for Beginners
Learn basic commands

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course