Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Methods Instance Methods

Antoine Boillot
Antoine Boillot
10,466 Points

mkdir -p [directory to create] : What does "-p" stand for ?

Hi all,

I've been through the Console foundations courses, but I cannot remember any use of of the "-p" command that Jason is using in this video.

What does "-p" stand for in "mkdir -p [directory to create]" ?

I would have done "mkdir [directory to create]"

Thanks a lot !

3 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

This works only in Linux and Mac if I remember correctly and allows you to create the directory and intermediate directories between your current position and the target directory using single console command instead of two or more. So let's say you want to have a directory with a path /documents/priority/tests/ - if you don't have that whole structure already in place, normally you would have to do it in three stages: mkdir documents & cd documents, mkdir priority & cd priority and finally mkdir test. With -p you can do it in one line: mkdir -p documents/priority/tests and it will create the whole directory tree if any parts of it are missing. If you try doing this without the -p and some of the directories in between do not exist, this will fail (or at least should :) ).

The -p will create the directory(along with the directories that lead to the directory you want to create) and would ignore any errors if the directory already exists. It is a argument/tag used in operating systems that are like unix or based on it. You can read more about it here mkdir(1) - Linux man page. I hope this helps.

Antoine Boillot
Antoine Boillot
10,466 Points

Crystal clear! Thank you both! :)