kmail.at
← learning

linux · difficulty ◆

mkdir — create directories

Make a directory. Then make a whole tree of them at once.

2026-08-17 · 4 min read

$ mkdir

What it does

mkdir creates one or more new directories. The name is a contraction of 'make directory'. By default it creates a single directory and refuses to create parent directories that do not exist — but the -p flag changes that, creating any missing parents along the way. It is one of the first commands you reach for when structuring a project or a filesystem layout.

Why it matters

Directories are how Unix organizes everything, and mkdir is the tool that builds them. It is also the quiet workhorse behind countless scripts and installers: `mkdir -p` is so common that it appears in almost every setup script, because it is idempotent — running it again on an existing path is harmless. Understanding mkdir means understanding how directory trees are actually constructed.

Example

$ mkdir projects
$ ls
notes.md  report.md
$ mkdir projects
$ ls
notes.md  report.md  projects

Creates a single directory named projects in the current folder.

$ mkdir -p src/components/ui
$ mkdir -p src/components/ui
$ find src -type d
src
src/components
src/components/ui

-p creates all missing parent directories at once, so the whole nested path appears in one command.

Common flags

-p
create parent directories as needed; no error if the path already exists
-v
verbose — print a message for each directory created
-m
set permissions on the new directory, e.g. -m 700
--
end of options — lets you create a directory whose name starts with a dash

History

Origin

mkdir has been part of Unix since the earliest editions in the early 1970s. Its name is simply a shortening of 'make directory'. The underlying system call, mkdir(2), is a fundamental filesystem primitive that the command-line tool wraps — which is why the command and the syscall share a name.

Fun fact

The -p flag (short for 'parents') is so widely relied upon that it is effectively the default behavior people expect. It is also what makes mkdir safe to run repeatedly in scripts: with -p, creating a directory that already exists is not an error, which is why installers and build tools call it over and over without checking first.

Related commands

← all learning