How to Create a Directory in Linux: Commands, Options, and Use Cases
Creating directories in Linux is one of the most fundamental filesystem operations — and while the basic command takes seconds to learn, there's a surprising amount of depth in how directories work, what options are available, and how your specific environment shapes the right approach.
The Core Command: mkdir
The primary tool for creating directories in Linux is mkdir (short for make directory). The basic syntax is:
mkdir directory_name For example:
mkdir projects This creates a directory called projects in your current working directory. That's the location your terminal session is currently pointing to, which you can check at any time with pwd (print working directory).
To create a directory in a specific location rather than your current one, provide an absolute path:
mkdir /home/username/documents/projects Or a relative path from your current location:
mkdir ../projects Creating Multiple Directories at Once
mkdir accepts multiple arguments, so you can create several directories in a single command:
mkdir docs images scripts This creates three separate directories side by side — useful when scaffolding a new project structure quickly.
The -p Flag: Creating Nested Directories 📁
One of the most commonly used mkdir options is -p (or --parents). Without it, trying to create a directory inside a path that doesn't yet exist will throw an error:
mkdir projects/2024/reports # Error if 'projects' or '2024' doesn't already exist Adding -p tells Linux to create the full path, including any missing intermediate directories:
mkdir -p projects/2024/reports This is particularly valuable when writing shell scripts that set up directory structures, since the command won't fail if the path already partially or fully exists.
Setting Permissions at Creation: The -m Flag
By default, new directories inherit permissions based on the umask — a system-level setting that defines default permission restrictions. On most Linux systems, this results in directories being created with 755 permissions (owner can read/write/execute; group and others can read/execute).
If you need specific permissions from the start, use the -m flag:
mkdir -m 700 private_data This creates the directory with permissions set to 700, meaning only the owner has access. This is a common approach for directories holding sensitive files like SSH keys or credentials.
Understanding whether to set permissions at creation or change them afterward with chmod depends on your workflow, security requirements, and whether other users or services will need access immediately.
Verifying the Directory Was Created
After running mkdir, you can confirm the result in a few ways:
ls— lists files and directories in the current locationls -la— shows detailed output including hidden items and permissionsls -ld directory_name— shows details specifically for that directory without listing its contents
ls -ld projects # drwxr-xr-x 2 username groupname 4096 Jul 10 09:15 projects The d at the start of the permissions string confirms it's a directory.
Key Variables That Affect Your Approach
| Factor | How It Shapes the Command |
|---|---|
| Shell environment | Bash, Zsh, and Fish all support mkdir, but script syntax may vary |
| User permissions | Creating directories in system paths requires sudo |
| Distribution | Most Linux distros behave identically for mkdir, but path conventions differ |
| Scripting vs. interactive use | Scripts benefit from -p and error handling; interactive use is usually simpler |
| Multi-user systems | Group ownership and umask settings matter more in shared environments |
Creating Directories That Require Root Access
Some locations — such as /etc/, /var/, or /usr/ — are protected and require elevated privileges. In those cases, prefix the command with sudo:
sudo mkdir /etc/myapp On systems where you're the sole user or working entirely within your home directory, this won't apply. On servers, shared workstations, or enterprise Linux environments, understanding permission boundaries becomes central to where and how you can create directories.
Directory Naming: Practical Considerations 🗂️
Linux directory names are case-sensitive, so Projects, projects, and PROJECTS are three distinct directories. A few naming habits that prevent headaches:
- Avoid spaces — use underscores (
_) or hyphens (-) instead, since spaces require quoting or escaping in the terminal - Keep names lowercase — reduces confusion when switching between case-sensitive and case-insensitive systems
- Avoid special characters like
!,*,?, or/in names, as these have specific meanings in shell environments
If a name with spaces is unavoidable, wrap it in quotes:
mkdir "my project" How Skill Level and Environment Change the Picture
For someone working interactively on a personal Linux desktop, mkdir with maybe the -p flag covers nearly every scenario. For a developer automating environment setup, the same command becomes part of larger shell scripts where error handling, conditional checks, and permission management all come into play. For a sysadmin managing multi-user servers, group ownership (chown, chgrp) and default ACLs often matter just as much as the mkdir command itself. ⚙️
The command is consistent across environments — what changes is how much of its surrounding context you need to control.