📁 Command: mkdir (Make Directory)
The mkdir command is used to create new folders (directories) in your Linux system. It is the digital equivalent of grabbing a new physical folder and labeling it for your documents.
1. The "Why"
Organizing your files is impossible without folders, mkdir is the command that builds the structure of your workspace.
2. Basic Syntax
mkdir [OPTIONS] DIRECTORY_NAME
- Example:
mkdir Projectscreates a folder named "Projects" in your current location.
3. Most Useful Flags
While creating one folder is simple, mkdir has powerful options for building complex structures instantly.
| Flag | Name | What it does |
|---|---|---|
-p |
Parents | Creates nested folders all at once (creates the path if it doesn't exist). |
-v |
Verbose | Prints a message for every directory created (useful to confirm success). |
-m |
Mode | Sets the file permissions (chmod style) at the exact moment of creation. |
4. Practical Examples
A. Creating Multiple Folders at Once
You don't have to run the command three times to make three folders. Just list them:
mkdir Photos Videos Documents
B. Building a Project Structure (The -p Power)
If you try to create Project/src/java but the Project folder doesn't exist yet, a normal mkdir will fail. Using -p tells Bash to "make the parents" as well:
mkdir -p Preader/src/main/java
C. Creating Folders with Specific Permissions
If you want to create a "Private" folder that only you can read, write, and enter:
mkdir -m 700 Private
D. Using Braces for Rapid Setup
You can use "brace expansion" to create a complex set of subfolders in one line:
mkdir -p dev/{css,js,assets,html}
This creates a dev folder containing four subfolders: css, js, assets, and html.
5. Pro-Tips
- Avoid Spaces: It is best practice in Linux to avoid spaces in folder names (e.g., use
My_Codeinstead ofMy Code). If you must use a space, wrap the name in quotes:mkdir "My Projects". - Check Before You Create: If you want to see exactly what
mkdiris doing, use the verbose flag:mkdir -pv work/client_1/invoicesOutput: mkdir: created directory 'work'; mkdir: created directory 'work/client_1'; mkdir: created directory 'work/client_1/invoices' - Arch Linux Context: You’ll use this often when setting up your system, such as
sudo mkdir /mnt/bootduring an installation ormkdir ~/.config/hyprfor your window manager.
6. Summary Reference
| Goal | Command |
|---|---|
| Create a single folder | mkdir folder_name |
| Create a folder path (nested) | mkdir -p path/to/folder |
| Create multiple folders | mkdir dir1 dir2 dir3 |
| Set permissions during creation | mkdir -m 755 folder_name |