What happens if parent directories exist?

QuestionsQuestions8 SkillsProDec, 13 2025
0104

That's a great question!

If the parent directories already exist when you use mkdir -p, the command will simply do nothing for those existing directories and proceed to create any new, non-existent directories in the path. It won't throw an error or try to overwrite them.

For example, if you already have:

projects/
└── alpha/

And then you run:

mkdir -p projects/alpha/docs
  • projects already exists, so mkdir -p skips creating it.
  • alpha already exists, so mkdir -p skips creating it.
  • docs does not exist, so mkdir -p creates it inside projects/alpha/.

So, mkdir -p is robust; it handles both cases where parent directories are missing and where they already exist without issues. It only creates what's needed.

Keep up the great work!

0 Comments

no data
Be the first to share your comment!