Linux command list

mkdir command: create directories

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying mkdir. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

mkdir [options] directory...

Names separated by spaces are all created.

Try it first

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.

The option worth knowing

OptionWhat it does
-pCreate missing parents too, and do not fail if the directory already exists

Building a whole path at once

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.

When you actually reach for it

SituationWhat to type
Make one scratch directorymkdir work
Lay out a known structuremkdir -p src/components src/utils
Inside a scriptmkdir -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.

Things that trip people up

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.

Practise it hands-on

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

rmdir / touch / ls

Frequently asked questions

What does mkdir stand for?
Make directory. It creates a new directory (folder).
How do I create a nested path in one go?
Add -p, as in mkdir -p docs/api/v1. Missing parents such as docs and docs/api are created too. Without -p, a missing parent is an error.
What happens if the directory already exists?
You get a File exists error. With -p, an existing directory is not treated as a failure.
Can I create several directories at once?
Yes. Separate the names with spaces, as in mkdir src tests docs, and each one is created.
How do I remove a directory I created?
Use rmdir if it is empty, or rm -r if it has contents.