Overview
mkdir creates the directories you name. It fails if a directory already exists or if a parent directory is missing, unless you use -p.
Background
A mkdir command appeared in Version 1 Unix, according to the FreeBSD and macOS manuals. Today the name covers GNU mkdir, the mkdir that macOS ships, and the mkdir applet in BusyBox. They agree on -p and -m with an octal mode, and differ on the wording and availability of -v.
Examples
Create one directory and confirm it exists:
mkdir reports && ls -d reports
Create a directory and any missing parents; -p is also quiet when the directory already exists:
mkdir -p reports/2026/q1 && ls reports/2026
Create several directories in one command:
mkdir one two && ls -d one two
Create a directory that only its owner can use; -m sets the permission bits and cut shows the first ten characters of the long listing:
mkdir -m 700 private && ls -ld private | cut -c1-10
Make sure a directory exists without an error if it already does:
mkdir -p cache && echo ok
Options
-p
Create missing parent directories and do not fail when the target already exists.
-m
Set the permission bits of the new directory, as in -m 700. Parents created by -p use the default
permissions.
Common mistakes
Without -p, mkdir a/b/c fails when a/b does not exist, and mkdir logs fails when logs exists. Quote names that contain spaces, or mkdir my docs creates two directories.
Portability
Only -p and -m with an octal mode are in the Common examples. The verbose option -v prints different text on GNU and BSD, and not every BusyBox build has it. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.