Exercise 4: Make A Directory (mkdir)

$ mkdir temp/stuff/things
$ mkdir -p temp/stuff/things/orange/apple/pear/grape

Where do you explain what “-p” is? Why is this there?
How did you add /orange/apple/pear/grape why not do that from the beginning?

-p is a “parents” argument in the mkdir command. Basically, if you want to make a specific file but don’t have the file tree set up as you want it, this will make all of the parent directories down to where you’re trying to go.
“/temp/stuff/” already exists so you don’t need to add -p in order to make “/things/”, but none of “/orange/…/grape/” exist as of that command, which is why -p is necessary

Close @koncerna, or maybe you are right. I always read -p as “path”, for “make the whole path”. Either way, the description of what it does is correct.

On the flip side, in PowerShell you don’t need -p.

1 Like

If I make multiple directories then it’s easier to just start with -p. There is no point of typing all directories multiple times.

If they’re already made, absolutely you can just change directories and make just the target folder, which makes -p redundant. If they’re not already made though, -p can be a shorthand, especially if you need to make long paths that branch off in multiple sections, or if you’re automating some folder creation process that you want to reuse later in either a different location or a different computer rather than using mkdir multiple times.