I tried to create folder in my local git repo using mkdir. It didn't work, but
mkdir -p
works.
Why?
I'm using Mac OS by the way. I checked the definition of mkdir -p. But I still don't quite understand.
I tried to create folder in my local git repo using mkdir. It didn't work, but
mkdir -p
works.
Why?
I'm using Mac OS by the way. I checked the definition of mkdir -p. But I still don't quite understand.
Say you're in the directory:
/home/Users/john
And you want to make 3 new sub directories to end up with:
/home/Users/john/long/dir/path
While staying in "/home/Users/john", this will fail:
mkdir long/dir/path
You would have to make three separate calls:
mkdir long
mkdir long/dir
mkdir long/dir/path
The reason is that mkdir by default only creates directories one level down. By adding the "-p" flag, mkdir will make the entire set in one pass. That is, while this won't work:
mkdir long/dir/path
this will work:
mkdir -p long/dir/path
and create all three directories.
From the help of mkdir: -p, --parents no error if existing, make parent directories as needed
So you failed maybe just because you wanted to create both parent and child folder in one shoot without -p option.
That flag will create parent directories when necessary. You were probably trying to create something with subdirectories and failing due to missing the -p flag