What is the purpose of the -p option?

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 -p will 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.

0 Comments

no data
Be the first to share your comment!