The -p flag allows missing parent directories to be created as needed.
With the exception of the set-gid bit, the current umask(2V) setting determines the mode in which directories are created. The new directory inherits the set-gid bit of the parent directory. Modes may be modified after creation by using chmod(1V).
mkdir requires write permission in the parent directory.