Ad space (banner)
🖥️Linux Lessons
Lesson 56 / 61

Creating Nested Directories at Once with mkdir -p

mkdir -p is for when "I want to create a deeply-nested folder, parent folders and all, in one go." Adding the -p option lets you create it even when the parent folders along the way don't exist yet.

Use it in the form mkdir -p path. A regular mkdir errors out if the parent folder is missing, but -p automatically creates every level needed.

Running mkdir -p projects/app/src creates all three levels — projects, then app, then src — at once, even if projects didn't exist yet.

A common early mistake is trying to create a deep path at once without -p, and hitting a "No such file or directory" error. Make -p a habit whenever you're creating a deep path.

In real work, mkdir -p is the standard way to batch-generate a project's skeleton folder structure via a script.

Linux
Try it (type this into the pseudo terminal)
mkdir -p projects/app/src

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)