What does the -p option do in the mkdir command?

The -p option in the mkdir command allows you to create parent directories as needed. This means that if any part of the specified path does not exist, it will be created automatically without raising an error.

Key Features:

  • Create Nested Directories: You can create a full directory path in one command, even if some of the parent directories do not exist.
  • No Error for Existing Directories: If a directory already exists, using -p will not cause an error; it will simply skip creating that directory.

Example:

If you run:

mkdir -p ~/project/digital_garden/resources/books

This command will create the entire path ~/project/digital_garden/resources/books, creating project, digital_garden, and resources if they do not already exist.

Using the -p option is particularly useful for organizing files and directories without needing to check if each parent directory exists beforehand. If you have any further questions or need more clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!