Can you explain 'mkdir -p'?

0106

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 -p will create all the necessary parent directories.

Example

If you run the following command:

mkdir -p /tmp/example/dir
  • If /tmp/example does not exist, it will create both example and dir directories.
  • If example already exists, it will only create dir inside it.

Using -p prevents errors if the parent directories already exist and simplifies the process of creating nested directory structures.

0 Comments

no data
Be the first to share your comment!