What does the -p flag do in "mkdir -p"?

92

35

What does the -p flag do in mkdir -p?

user27449

Posted 2010-07-19T04:21:20.480

Reputation: 5 104

8man mkdir, will give you the information. – Johan – 2010-07-19T05:24:40.530

Hardly a helpful comment.... – ShaneC – 2019-10-24T10:52:06.970

Answers

130

The -p flag will create nested directories, but only if they don't exist already.

For example, suppose you have a directory /foo that you have write permissions for.

mkdir -p /foo/bar/baz  # creates bar and baz within bar under existing /foo

It is also an idempotent operation, because if you run the same command over again, you will not get an error, but nothing will be created.

Eric Wendelin

Posted 2010-07-19T04:21:20.480

Reputation: 1 713