Search code examples
macosmkdir

mkdir -p for one path segment


I understand the use of mkdir -p for cases like: mkdir -p foo/bar where neither of those directories yet exists, which I was surprised to see someone using mkdir -p bar. Does it ever make sense to use -p when there is no / in the following argument, i.e. there is only one path segment?

My understanding is that mkdir -p foo is equivalent to mkdir foo in all cases. Is there a case I'm missing?


Solution

  • mkdir foo will report an error if a directory named "foo" already exists; mkdir -p foo will not. Essentially, in this case the -p just tells mkdir that it's ok if the directory already exists.