The -p Flag Is Not About Saving Keystrokes

-p is best known as the flag that creates the missing directories along the way.
But there is a second reason it shows up in almost every script you will ever read.
It does not fail when the directory is already there.
A plain mkdir logs stops with File exists the second time it runs, and in a script that quits on the first error (set -e), nothing after that line ever happens. Setup scripts, Dockerfiles, CI jobs: they all live in a world where the same step runs again and again, and -p is what makes run number ten end exactly like run number one.
That property has a name, idempotency: running something twice leaves you where running it once did. Infrastructure tools like Ansible and Terraform are built entirely on this idea, and a one letter flag is the door into it.
The trade is real, though. -p never complains, so a typo like mkdir -p /var/logg/app gets built exactly as typed. Convenience was bought by giving up the error that would have told you the path was wrong.
Next time you reach for -p, notice which one you are buying: the shortcut, or the promise that it is safe to run again.
