mkdir — make directory — creates new folders. It looks trivial until the day you need a five-level tree in one command, at which point the -p flag becomes your favourite keystroke.
Create one or many #
$ mkdir photos
$ mkdir 2025 2026 archive
The second line creates all three names in one pass — mkdir accepts any number of arguments.
Nested trees with -p #
Without flags, mkdir fails if any parent on the path is missing. With -p it creates every missing level in one shot — and stays silent if the target already exists, which makes it safe in scripts:
$ mkdir -p projects/aospix/{src,docs,tests}
$ find projects -type d
projects
projects/aospix
projects/aospix/src
projects/aospix/docs
projects/aospix/tests
The brace expansion {src,docs,tests} is shell trickery, not mkdir's, but the pair together is the fastest way to scaffold a layout. The example uses find to prove the result.
Permissions at creation #
-m sets the mode while creating, instead of creating and then running chmod afterwards:
$ mkdir -m 700 secrets
$ ls -ld secrets
drwx------ 2 ana ana 4096 Oct 21 09:00 secrets
Good to know #
| Command | Result |
|---|---|
mkdir photos | Fails if photos already exists |
mkdir -p photos | Succeeds silently if photos exists |
mkdir -p a/b/c | Creates any missing parents |
mkdir -m 755 shared | Creates with specific permissions |
A tidy tree makes every other command easier: cp and mv both behave better when the destination exists. The full terminal notes series builds a working toolkit one command at a time.
