How to use the SSH mkdir command
Creating and organizing directories on your Linux hosting account is an essential skill for efficient file management. In particular, the SSH mkdir command is a powerful tool that allows you to create new directories quickly and efficiently through your terminal. Furthermore, this comprehensive guide will teach you everything you need to know about using the mkdir command, from basic directory creation to advanced techniques that will streamline your server management workflow.
Understanding the SSH mkdir Command
The mkdir (make directory) command is a fundamental Linux utility used to create new directories on your server. Unlike file creation commands, mkdir specifically handles directory structures, making it essential for organizing your website files, logs, backups, and application data. Moreover, it provides various options that give you precise control over how directories are created and configured.
Whether you’re setting up a new website structure, organizing uploaded files, or creating backup directories, mastering the mkdir command will significantly improve your server management efficiency.
Basic Syntax of the mkdir Command
The fundamental syntax of the mkdir command follows this simple pattern:
mkdir [options] directory_nameWhere:
- directory_name is the name of the directory you want to create
- [options] are optional flags that modify the command’s behavior
- You can specify either relative or absolute paths
Creating a Single Directory
To create a single directory, simply specify the directory name or path:
mkdir myNewDirectoryExample: Creating a directory for website backups:
mkdir ~/backupsYou can also create a directory with a specific path:
mkdir /home/username/public_html/imagesAs a result, this creates an “images” directory inside your public_html folder.
Creating Multiple Directories at Once
Instead of running multiple commands, you can create several directories simultaneously by listing them in a single command:
mkdir uploads downloads documents archivesPractical example: Setting up a complete website structure:
mkdir css js images fonts videosConsequently, this creates all five directories for your website assets in one efficient command.
Creating Nested Directories with Parent Paths
One of the most powerful features of mkdir is the ability to create nested directory structures. However, by default, mkdir will fail if the parent directories don’t exist. Fortunately, the -p (parents) option solves this problem by creating all necessary parent directories automatically:
mkdir -p ./this/is/a/nested/directoryReal-world example: Creating an organized backup structure:
mkdir -p ~/backups/2026/february/databaseThis command creates the entire directory hierarchy in one step, even if none of the parent directories exist yet.
Another example: Setting up a project structure:
mkdir -p ~/projects/myapp/{src,tests,docs,config}This creates multiple subdirectories under the projects/myapp path using brace expansion.
Setting Directory Permissions During Creation
You can set specific permissions for a directory at the time of creation using the -m (mode) option:
mkdir -m 755 public_directoryExample: Creating a private directory with restricted access:
mkdir -m 700 ~/private_filesThis creates a directory that only you can read, write, and execute.
Common permission values:
- 755 – Owner has full access, others can read and execute
- 750 – Owner has full access, group can read and execute, others have no access
- 700 – Only owner has full access
- 775 – Owner and group have full access, others can read and execute
Advanced mkdir Command Options
Moreover, enhance your directory creation with these powerful options:
-v (verbose): Displays a message for each created directory
mkdir -v new_directoryOutput: mkdir: created directory 'new_directory'
-p (parents): Creates parent directories as needed, and doesn’t return an error if the directory already exists
mkdir -p ~/website/assets/images/thumbnails-m (mode): Sets file permissions at creation time
mkdir -m 644 limited_directoryCombining options: You can use multiple options together for maximum efficiency
mkdir -pv -m 755 ~/public_html/blog/images/2026This creates the entire path, shows verbose output, and sets appropriate permissions—all in one command.
Common Use Cases for Web Hosting
In practice, here are typical scenarios where the mkdir command proves invaluable for web hosting management:
1. Setting up a new website structure:
mkdir -p ~/public_html/{css,js,images,uploads,includes}2. Creating organized backup directories:
mkdir -p ~/backups/{daily,weekly,monthly}/{database,files}3. Organizing log files by date:
mkdir -p ~/logs/$(date +%Y)/$(date +%m)4. Creating WordPress theme directory structure:
mkdir -p ~/public_html/wp-content/themes/mytheme/{css,js,images,templates,inc}5. Setting up development and staging environments:
mkdir -p ~/{development,staging,production}/public_html6. Creating user upload directories with proper permissions:
mkdir -m 755 -p ~/public_html/uploads/{images,documents,videos}Best Practices and Tips
Therefore, to ensure efficient directory management and avoid common pitfalls, follow these best practices:
- Always use descriptive names for directories to make your file structure self-documenting
- Implement consistent naming conventions such as lowercase with hyphens or underscores
- Leverage the -p flag when creating nested structures to save time and avoid errors
- Set appropriate permissions using the -m option during creation rather than changing them afterward
- Enable verbose mode (-v) when creating multiple directories to confirm successful creation
- Plan your directory structure before creating it to ensure logical organization
- Avoid spaces in directory names or use quotes if spaces are necessary
- Use absolute paths when working with critical directories to prevent mistakes
Pro tip: You can combine mkdir with other commands using the && operator:
mkdir -p ~/newproject/src && cd ~/newproject/srcThis creates the directory and immediately navigates into it.
New Hosting Plan with 80% OFF
Upgrade your website’s home without the heavy bill. Get new hosting plan with a huge 80% discount and enjoy reliable performance, free SSH access, and full Linux terminal support. Run commands, manage files, and configure your hosting directly. Perfect for developers, power users, or anyone who prefers the control of a Linux environment.
Need More Help?
Remember that proper directory organization is the foundation of good server management. Nevertheless, with practice, creating and managing directories on your Linux hosting will become second nature, allowing you to focus on building and maintaining your websites with confidence.


