mkdir -p foo
Note that this will also create any intermediate directories that don’t exist; for instance,
mkdir -p foo/bar/baz
will create directories
foo/bar/baz if they don’t exist.
Some implementation like GNU
mkdir --parents as a more readable alias, but this is not specified in POSIX/Single Unix Specification and not available on many common platforms like macOS, various BSDs, and various commercial Unixes, so it should be avoided.
If you want an error when parent directories don’t exist, and want to create the directory if it doesn’t exist, then you can
test for the existence of the directory first:
[ -d foo ] || mkdir foo