The -p option in the mkdir command is used to create parent directories as needed. This means that if you specify a directory path that includes one or more parent directories that do not exist, mkdir -p will create those parent directories automatically.
Purpose:
- Create Nested Directories: It allows you to create a complete directory structure in one command without having to create each parent directory individually.
- No Error for Existing Directories: If the specified directory or any of its parent directories already exist,
mkdir -pwill not raise an error; it will simply skip creating those existing directories.
Example:
mkdir -p /home/user/documents/projects
In this example, if documents does not exist, it will be created along with the projects directory. If documents already exists, it will not cause an error, and only projects will be created if it does not exist.
