In server administration, backend web development, and cloud systems engineering, structuring your file system to organize files, isolate components, or set up new website environments is a fundamental task. The mkdir command stands for Make Directory. It is a core POSIX-standard terminal utility used explicitly to create new, empty folders within your server’s filesystem.
Using this command lets you build clean directory architectures for your projects instantly without needing a visual file manager.
Table of Contents
Direct Folder Creation and Primary Command Flags
The basic syntax for creating a directory requires passing the command followed by your desired folder name: mkdir new_folder. To handle nested subfolders, track creation events, or set explicit folder access rules, you will regularly append these core operational flags:
1. Building Nested Parent Paths Automatically (mkdir -p)
By default, if you try to create a deeply nested folder path (such as modules/assets/images) when the top folders do not exist yet, the standard mkdir command will fail and throw a “No such file or directory” error. The -p (parents) flag fixes this by automatically creating all missing parent directories along the path.
- The Action: Run the parents flag followed by your complete desired nested path:
mkdir -p modules/assets/images - Operational Benefit: This is the most efficient way to set up complete, multi-tiered directory structures for a new website feature or plugin layout in a single keystroke. It also skips throwing an error if the directory path already exists.
2. Confirming Creations with Verbose Mode (mkdir -v)
By default, when mkdir executes successfully, the terminal remains completely silent and simply displays a fresh command prompt line. The -v (verbose) flag forces the server to output a live confirmation message detailing every directory it creates.
- The Action: Combine the verbose flag with the parents flag to monitor structural setups:
mkdir -pv custom-plugin/includes/css - The Output Returned: The terminal will print a clear step-by-step log of its actions:
mkdir: created directory 'custom-plugin' mkdir: created directory 'custom-plugin/includes' mkdir: created directory 'custom-plugin/includes/css'
3. Hardcoding Initial Access Permissions (mkdir -m)
When you create a folder normally, the server automatically applies default system permissions (usually 755 or 775). The -m (mode) flag allows you to set explicit file system permission bits right at the moment of creation.
- The Action: Pass the exact octal configuration value alongside your target folder name:
mkdir -m 700 secure_vault - Operational Benefit: This instantly locks down highly sensitive paths-such as folders meant for private cryptographic keys or internal database backups-ensuring only your specific user account can read or write data there.
Working with Absolute Brand Directory Paths
You can provision folder frameworks anywhere in your server account by leveraging absolute paths. When setting up directories inside your brand layout, ensure your paths are mapped cleanly from your home root:
Structuring a New Testing Target In-Place
To add a dedicated temporary log folder inside your primary website directory, execute a direct relative path command:
mkdir public_html/temp_logs
Deploying a Staging Folder via Absolute Pathing
To build a clean staging directory branch for an independent domain name within your brand environment, use explicit absolute targeting:
mkdir -p /home/mybox/yourlogin/yourwebsite.com/public_html/staging-v2