That's a very important question directly related to the mkdir command and its -p option!
If you use the mkdir command without the -p (parents) option, and any of the parent directories in the specified path do not exist, the command will fail and return an error.
Let's illustrate with an example:
Suppose you want to create a directory /home/labex/project/digital_garden/notes/my_first_note, but the notes directory does not yet exist.
-
Without
-p:mkdir /home/labex/project/digital_garden/notes/my_first_noteThis command would likely produce an error message similar to:
mkdir: cannot create directory ‘/home/labex/project/digital_garden/notes/my_first_note’: No such file or directoryThis happens because the system can't create
my_first_noteinsidenotesifnotesitself isn't there. You would have to createnotesfirst, thenmy_first_note. -
With
-p:mkdir -p /home/labex/project/digital_garden/notes/my_first_noteThis command would successfully create
notes(if it didn't exist) and then createmy_first_noteinside it, without any errors.
So, in short:
mkdir(without-p): Fails if parent directories don't exist.mkdir -p: Automatically creates any necessary parent directories that don't exist.
For the current step, we're creating notes, projects, and resources inside digital_garden. Since you already created digital_garden in the previous step, these mkdir commands will work fine without -p. However, if you were creating a deeper structure (like digital_garden/notes/quick_thoughts) and notes didn't exist, you'd find mkdir -p very handy!
Does that make sense? Let me know if you have any more questions!