"Make new directory"
The mkdir command makes directories (folders). It's like creating a new folder in your file manager, but from the command line. You can make one folder or a whole bunch at once.
mkdir - make directories
mkdir stands for make directory.
You'll typically use the mkdir command with directory names and paths similar to how you navigate your filesystem.
For example:
mkdir [options] [directory_name]The most basic use - just make one new folder in your current location.
mkdir my_folder<REPLACE_WITH_IMAGE_OR_GIF>
Instead of running mkdir three times, you can create several folders in one command by listing them with spaces.
mkdir folder1 folder2 folder3<REPLACE_WITH_IMAGE_OR_GIF>
Create a folder somewhere else on your system by specifying the complete path to where you want it.
mkdir ~/Documents/new_project<REPLACE_WITH_IMAGE_OR_GIF>
This is the magic option! The -p flag creates "parent" directories - meaning if you want to create folder1/folder2/folder3 but folder1 and folder2 don't exist yet, it'll create them all for you.
mkdir -p projects/web/frontend<REPLACE_WITH_IMAGE_OR_GIF>
You can create entire directory trees in one command. This creates the app folder, then src and assets inside it, then css and js inside src.
mkdir -p app/src/{css,js} app/assets<REPLACE_WITH_IMAGE_OR_GIF>
Combine the -p option with paths from your home directory to build folder structures anywhere.
mkdir -p ~/Documents/projects/website/images<REPLACE_WITH_IMAGE_OR_GIF>
If you try to create nested directories without -p, mkdir will complain that the parent directories don't exist. That's when you know you need the -p flag!
mkdir folder1/folder2/folder3
# This fails! Use mkdir -p instead<REPLACE_WITH_IMAGE_OR_GIF>
| Command | What It Does | Example |
|---|---|---|
mkdir folder |
Create single directory | mkdir documents |
mkdir folder1 folder2 |
Create multiple directories | mkdir photos videos music |
mkdir ~/path/folder |
Create directory at specific path | mkdir ~/Desktop/new_project |
mkdir -p path/to/folder |
Create nested directories | mkdir -p projects/app/src |
mkdir -p {dir1,dir2}/sub |
Create multiple nested structures | mkdir -p {web,mobile}/assets |
Use -p whenever you want to create a folder inside another folder that might not exist yet. It's like saying "create this path, and if any parent folders are missing, create those too."
mkdir folder1/folder2
# Error: mkdir: folder1: No such file or directoryThis error means folder1 doesn't exist, so mkdir can't create folder2 inside it. Add -p to fix this!
The curly brace syntax {dir1,dir2} is super handy for creating multiple similar structures:
mkdir -p project/{frontend,backend}/{src,tests}This creates:
- project/frontend/src
- project/frontend/tests
- project/backend/src
- project/backend/tests
If your directory name has spaces, wrap it in quotes:
mkdir "My New Project"
mkdir -p "Documents/My Projects/Website Files"