In the beginning, there was only the bare
mkdir command. In accordance with Unix's design principles, this simple command performed one simple task: creating a directory.
mkdir acquired a
-p option to handle a common use case where the caller wants to create zero, one or more directories to ensure that a particular path exists. This was not made the default operation for several reasons. First, not all systems had this more complex feature, and requiring the
-p option meant that scripts that used it would get a reasonable error message (something like
mkdir: invalid option -z) rather than strangely failing to create directories occasionally. Second, and most importantly, the behavior of
mkdir -p is not a compatible replacement of
mkdir in all cases.
In particular, on most fileystems,
mkdir is an atomic operation. If a program runs
mkdir playground and the command succeeds, the program knows that it created the
playground directory. This allows the program to treat the new directory as its exclusive playground: if another instance of the same program is running concurrently, its call to
mkdir playground will fail. This property is obviously not provided by
mkdir -p since it allows the argument to exist.
mkdir -p had existed from the start, it could have been made the default mode, with something like
mkdir -a for the single-directory creation command. But that would not have followed the usual Unix design philosophy: most basic utilities are simple wrappers around the underlying primitives, with fancier behavior (like creating multiple directories in one go) requiring fancy options.