Create nested directories with mkdir -p
Build a whole folder path in one go instead of cd-ing and mkdir-ing level by level.
Run mkdir -p path/to/deep/folder — every missing level is created in one shot.
01Command
Command
$ mkdir -p ~/projects/2026/sep/photos && mkdir -p /var/www/site/{css,js,img}02What it does
Without -p, mkdir fails if any parent directory is missing. With -p it creates the entire chain and stays silent if directories already exist, so the command is safe to re-run in scripts. Brace expansion like {css,js,img} creates several sibling folders at once.
03Risk
!Warning: mkdir -p will happily create folders in the wrong place if you mistype the path (e.g. relative to the current directory). Double-check absolute paths starting with / before running, since fixing a misplaced tree means moving or deleting it afterwards.
04Undo
Undo
$ rmdir ~/projects/2026/sep/photos (only removes if empty)05Sources
- mkdir(1) — Linux manual pageEvidence: mkdir -p creates the named directories including any missing parent directories, and does not complain if they already exist.
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
Search text recursively in a directory with grep
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Extract a .tar.gz archive with tar
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Check free disk space on each filesystem with df
Show total, used, and available space plus usage percentage for every mounted filesystem in human-readable units.