Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,440 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! :)