mkdir — Create Directories in Linux
Create single or nested directories with mkdir. Master -p for deep paths and brace expansion to scaffold entire project structures in one command.
mkdir (make directory) creates new folders. It seems simple, but the -p flag combined with brace expansion lets you scaffold an entire project skeleton — directories, subdirectories, the whole tree — in a single command.
Options
mkdir Options
| Option | Long Form | Description |
|---|---|---|
-p | --parents | Create parent directories as needed — no error if already exists |
-m MODE | --mode=MODE | Set permissions on creation (e.g. 755) |
-v | --verbose | Print a message for each directory created |
Basic Creation
mkdir new_folder # Create a single directory
mkdir dir1 dir2 dir3 # Create multiple at onceNested Directories with -p
Without -p, every parent directory in the path must already exist. With -p, mkdir creates the entire chain — parents, children, grandchildren — in one shot. It also doesn't fail if the directory already exists, making it safe to use in scripts.
# Without -p — fails if parent doesn't exist
mkdir parent/child/grandchild
# mkdir: cannot create directory 'parent/child/grandchild': No such file or directory
# With -p — creates the entire path
mkdir -p parent/child/grandchild # ✓ Works always
# Verbose: see exactly what was created
mkdir -pv a/b/c
# mkdir: created directory 'a'
# mkdir: created directory 'a/b'
# mkdir: created directory 'a/b/c'Brace Expansion — Scaffold Projects Instantly
Brace expansion {a,b,c} is a shell feature (not specific to mkdir) that expands into multiple arguments. Combined with mkdir -p, you can create complex directory trees with one line.
# Simple: create src, docs, tests under project/
mkdir -p project/{src,docs,tests}
# Creates:
# project/src/
# project/docs/
# project/tests/
# Nested: multi-level project structure
mkdir -p project/{src/{components,utils,hooks},docs,tests/{unit,e2e}}
# Creates:
# project/src/components/
# project/src/utils/
# project/src/hooks/
# project/docs/
# project/tests/unit/
# project/tests/e2e/
# Numerical ranges
mkdir -p logs/{2023,2024,2025}/{jan,feb,mar}
# Creates year/month foldersSetting Permissions
mkdir -m 755 public_dir # rwxr-xr-x — anyone can read
mkdir -m 700 private_dir # rwx------ — owner only (good for .ssh)
mkdir -m 777 shared_dir # rwxrwxrwx — everyone can writeYou want to create `~/projects/webapp/src/components` but none of the intermediate directories exist. Which command works?
Scaffold a full project structure in one command:
Create this tree using a single mkdir -p with brace expansion:
myapp/
├── src/
│ ├── components/
│ ├── api/
│ └── utils/
├── public/
├── tests/
└── docs/
Then verify with tree myapp or ls -R myapp.