How to Create a Directory on Linux: Commands, Options, and Use Cases

Creating directories is one of the most fundamental tasks in Linux — and while the basic command takes seconds to learn, there's meaningful depth underneath it that affects how you organize files, set permissions, and structure projects across different environments.

The Core Command: mkdir

The primary tool for creating directories on Linux is mkdir (short for make directory). At its simplest:

mkdir foldername 

This creates a new directory called foldername in your current working location. If you're unsure where you are in the filesystem, run pwd (print working directory) first.

You can also specify an absolute path to create a directory anywhere on the system, regardless of where you currently are:

mkdir /home/username/projects/newproject 

Or a relative path, which builds from your current directory:

mkdir ../siblingfolder 

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. It's faster than running the command individually for each one — especially useful when setting up a project structure from scratch.

The -p Flag: Creating Nested Directories 📁

One of the most practical mkdir options is -p (parents). Without it, trying to create a deeply nested path where intermediate directories don't yet exist will throw an error:

mkdir /home/username/projects/2024/client/assets # Error if 'projects', '2024', or 'client' don't exist yet 

Adding -p tells Linux to create all missing intermediate directories automatically:

mkdir -p /home/username/projects/2024/client/assets 

The -p flag also suppresses errors if the target directory already exists — which makes it safe to use in scripts where you're not certain about the current state of the filesystem.

Setting Permissions at Creation: -m

By default, a new directory inherits permissions based on the system's umask value — a system-wide mask that subtracts permissions from the default. On most Linux systems, this results in directories created with 755 permissions (owner can read/write/execute; group and others can read/execute).

If you need specific permissions from the moment of creation, use the -m flag:

mkdir -m 700 privatefolder 

This creates the directory with 700 permissions — only the owner has any access. This is particularly relevant when:

  • Creating directories that will store sensitive data (SSH keys, config files, credentials)
  • Setting up shared environments where access control matters
  • Scripting automated deployments where permissions need to be predictable

You can combine flags. For example, creating nested directories with restricted permissions:

mkdir -p -m 750 /srv/app/config 

Variables That Change the Approach 🔧

How you create directories — and which options matter — depends on several factors:

FactorWhat It Affects
User privilege levelWhether sudo is needed for certain paths
Filesystem typeSome filesystems (like FAT32) don't support Linux permissions
Shell scripting vs. interactive useScripts benefit from -p to avoid failure on existing paths
Security requirementsSensitive directories need explicit permission flags
Shared/multi-user systemsGroup ownership and permissions become more critical

Privilege and sudo

Standard users can create directories within their own home directory without elevated permissions. Trying to create directories in system paths like /etc/, /usr/, or /var/ typically requires sudo:

sudo mkdir /etc/myapp 

Without the right privileges, you'll see a "Permission denied" error — not a sign of a broken command, just a permissions boundary doing its job.

Using the GUI File Manager (When Available)

On Linux distributions with a desktop environment — GNOME, KDE, XFCE, and others — you can create directories graphically:

  • Right-click inside a folder in the file manager
  • Select "New Folder" or equivalent
  • Name it and confirm

This produces identical results to mkdir from the terminal. The choice between GUI and CLI is mostly about workflow preference, though the command line is faster for bulk creation or scripted tasks.

Verifying the Directory Was Created

After running mkdir, confirm it worked with:

ls -la 

This lists directory contents in long format, including hidden files and permission details. You should see your new directory listed with a d at the start of its permission string — for example, drwxr-xr-x.

Directory Naming Considerations

Linux filenames are case-sensitive, so Documents, documents, and DOCUMENTS are three distinct directories. A few practical naming points:

  • Spaces in directory names are valid but require quoting or escaping: mkdir "my folder" or mkdir my folder
  • Special characters (beyond hyphens and underscores) can complicate scripting and should generally be avoided
  • Names starting with a dot (.) create hidden directories — visible with ls -a but hidden from standard ls output

Different Environments, Different Defaults 📌

The behavior of mkdir is consistent across Linux distributions — it's part of the GNU Core Utilities — but the context shapes what you'll do with it:

  • Server environments running headless (no GUI) make terminal-based directory creation the only practical option
  • Developer workstations often combine GUI file management with terminal use depending on the task
  • Container and cloud environments (Docker, CI/CD pipelines) rely heavily on scripted mkdir -p calls to prepare directory structures reliably
  • Shared hosting or restricted shells may limit where directories can be created and what permissions can be set

The right approach for creating directories on Linux isn't one-size-fits-all — it depends on your permission level, whether you're working interactively or scripting, the depth of the directory structure you need, and the security requirements of what you're storing.