mkdir: create directories

Updated November 2026

mkdir creates directories. With -p it creates a whole path in one go and does not complain if the directory already exists, which makes it safe in scripts.

mkdir [options] directory ...

Common options

OptionMeaning
-pCreate parent directories as needed; no error if it exists
-m modeSet the permissions of the new directory
-vPrint each directory created

Examples

mkdir projects                          # one directory
mkdir docs images scripts               # several at once
mkdir -p /srv/app/releases/2026-11-02   # the whole path
mkdir -m 700 ~/private                  # only you can enter it
mkdir -p site/{css,js,img}              # brace expansion (bash, zsh): three directories
mkdir -p logs/{2025,2026}/{01..12}      # 24 directories for two years of months

Temporary directories

For scratch space in scripts, use mktemp -d instead of a fixed name in /tmp. It creates a new, private directory with a random name:

work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
echo "working in $work"

Things to know