The command mkdir -p is used in Unix-like operating systems to create directories. Here's a breakdown of its components:
-
mkdir: This stands for "make directory" and is the command used to create new directories. -
-p: This is an option (or flag) that stands for "parents." It allows the creation of parent directories as needed. If the specified directory structure does not exist,mkdir -pwill create all the necessary parent directories.
Example
If you run the following command:
mkdir -p /tmp/example/dir
- If
/tmp/exampledoes not exist, it will create bothexampleanddirdirectories. - If
examplealready exists, it will only createdirinside it.
Using -p prevents errors if the parent directories already exist and simplifies the process of creating nested directory structures.
