Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
Cupertino desk6 min

The `mkdir` Command: Create Directories in Linux, macOS, Unix, Windows, and PowerShell

A practical guide to mkdir across Linux, macOS, Unix, Windows Command Prompt, and PowerShell, including nested paths, permissions, scripting, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

mkdir means “make directory.” On Unix-like systems, mkdir -p project/src creates the complete directory path, including missing parents. The exact command differs across POSIX shells, Windows Command Prompt, and PowerShell, so use the syntax for your environment.

What mkdir does

The command creates one or more directory entries in the filesystem. It does not change into the new directory, create a file, delete or overwrite an existing directory, or grant permissions you do not have.

On POSIX systems, the utility ultimately uses the mkdir() filesystem operation. Newly created permissions are affected by the process’s umask and, on some systems, ACLs or mandatory access controls.

Basic syntax on Linux, macOS, and Unix

mkdir [OPTION]... DIRECTORY...

Typical examples:

mkdir project
mkdir src tests docs
mkdir ./reports/2026
mkdir /tmp/demo
mkdir "$HOME/projects"

A relative path is resolved from the current working directory; an absolute path is independent of where the command is run. In shells such as Bash, ~ is expanded by the shell, not by mkdir:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mkdir ~/Documents/archive

Creating nested directories with -p

mkdir -p project/src/components

-p (or GNU --parents) creates missing parent directories. It also succeeds when the final path already exists as a directory, making it useful for repeatable setup commands.

mkdir -p app/config/production
mkdir -p existing-directory

It does not replace a file:

mkdir -p existing-file/child

This fails because a regular file cannot be a parent directory. GNU mkdir -p also does not change existing parent permissions, and its -m setting does not precisely control newly created intermediate parents.

Names, paths, and multiple directories

Several directories

mkdir src test docs

Operands are processed in order. If a later operand fails, earlier directories may already have been created; there is no automatic rollback.

Spaces and special characters

Quote paths containing spaces:

mkdir "Project Files"
mkdir "/tmp/Client Archive"
mkdir -p "$backup_root/$date"

Without quotes, the shell treats each whitespace-separated word as a separate operand.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Names beginning with a hyphen

mkdir -- "-draft"
mkdir ./-draft

-- ends option parsing on GNU and many Unix implementations. Using ./ is a useful alternative; unusually old implementations may not support --.

Brace expansion

mkdir -p project/{src,tests,docs}

Brace expansion is performed by shells such as Bash and Zsh, not by mkdir. For strictly POSIX shell scripts, write the paths explicitly:

mkdir -p project/src project/tests project/docs

Permissions with -m

mkdir -m 755 public
mkdir -m 700 private
mkdir -m 775 team
mkdir -m 1777 shared

-m requests the mode for newly created command-line directories; it does not guarantee the final bits. A common Linux calculation is requested mode & ~umask & 0777, and ACLs or security policy can also affect the result.

  • 755: owner can read, write, and search; others can read and search.
  • 700: only the owner has those permissions.
  • 775: owner and group can read, write, and search; others can read and search.
  • 1777: everyone can use the directory, while the sticky bit restricts deletion or renaming of other users’ entries.

Directory permission letters have a different practical meaning from file permissions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Read (r): list names in the directory.
  • Write (w): create, remove, or rename entries, subject to other rules.
  • Execute/search (x): enter the directory and access items when their names are known.

Symbolic modes are also supported by GNU and POSIX implementations:

mkdir -m u=rwx,go=rx shared
mkdir -m g+w team
mkdir -m a-rwx,u=rwx private

Check the effective result instead of assuming the requested mode was applied:

umask
stat -c '%A %a %n' private

The GNU stat format above is platform-specific. On systems with a BSD-style stat, a local equivalent may be:

stat -f '%Sp %Lp %N' private

Useful GNU options

Option Purpose
-m MODE Request permissions for newly created command-line directories.
-p Create missing parents and accept an existing final directory.
-v Print each directory as it is created.
-Z / --context Set an SELinux security context where supported.
--help Display GNU help.
--version Display the GNU version.
mkdir -v -p project/src project/tests

Verbose message wording is implementation-dependent, and options such as -Z are not portable POSIX features.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reliable use in shell scripts

#!/bin/sh
set -eu

root=${1:?usage: $0 ROOT}
if mkdir -p "$root/src" "$root/tests" "$root/docs"; then
    printf 'Directory tree is readyn'
else
    printf 'Could not create directories under %sn' "$root" >&2
    exit 1
fi
  • Quote every variable expansion and path that may contain whitespace.
  • Use -p when missing parents are expected.
  • Check the exit status; successful mkdir returns zero, failure returns nonzero.
  • Do not use eval to assemble a command from input.
  • Do not hide diagnostics with 2>/dev/null unless you deliberately handle the status.

mkdir -p is idempotent for an existing directory, but that can conceal a configuration error when the directory should have been absent. Directory creation alone is not a complete lock protocol: concurrent processes can change the path immediately afterward. A simple lock attempt can use:

if mkdir "$lockdir" 2>/dev/null; then
    # Lock acquired
else
    # Another process probably owns it
fi

Troubleshooting failures

File exists

Without -p, this usually means the target directory already exists. Use -p only when that is an acceptable result. If the existing path is a file, -p still fails.

No such file or directory

A parent is missing and -p was not supplied, or a path component is invalid. Try mkdir -p path/to/target.

Not a directory

A component in the path is a regular file or another non-directory object.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Permission denied

You may lack write permission on the parent or search permission on an ancestor. Other causes include a read-only filesystem, SELinux or another mandatory access-control policy, a network filesystem restriction, quotas, or exhausted storage.

pwd
ls -ld parent
df -h .
df -i .
mount | grep ' on '

sudo mkdir can address an ownership or privilege issue, but it should not be the default remedy: root-created paths can prevent your normal account from modifying them later.

Read-only file system or No space left on device

Check the mount state and both block space (df -h) and inode space (df -i). A quota or network policy may also reject creation.

Unexpected location or symlink

Print the working directory when debugging:

printf 'Working directory: %sn' "$PWD"

Symlinks in a path can redirect creation or fail when dangling; the final component cannot be created as a directory when it names a symbolic link. Security-sensitive scripts should avoid untrusted paths in world-writable directories and account for symlink races.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Windows Command Prompt

In cmd.exe, mkdir and md are equivalent commands:

mkdir Reports
md Reports
mkdir C:TaxesPropertyCurrent
mkdir "C:Project FilesArchive"

With command extensions enabled (the documented default), Windows CMD can create intermediate directories. Windows uses backslashes conventionally and does not use Unix modes such as 755 or 700.

PowerShell

The explicit PowerShell form is:

New-Item -ItemType Directory -Path .Reports
New-Item -Path . -Name "Reports" -ItemType Directory
mkdir .src
mkdir .srccomponents

PowerShell documents mkdir and md as shorthand functions for creating a directory through New-Item, rather than necessarily invoking a Unix executable. A successful New-Item returns a DirectoryInfo object.

New-Item -ItemType Directory -Path .build -Force

-Force returns an existing folder object when appropriate; it does not overwrite a nonempty directory or destroy its contents.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

mkdir versus mkdir()

mkdir is a command-line utility. mkdir() is the POSIX/C interface:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#include <sys/stat.h>

int mkdir(const char *path, mode_t mode);

The function returns 0 on success and -1 on failure, setting errno. It does not implement the utility’s -p behavior; a program must create each missing parent or use a higher-level API.

Alternatives

install -d

install -d -m 755 -o appuser -g appgroup /srv/app

GNU install -d is useful in deployment scripts when ownership and permissions must be set together, but it is less portable and ownership changes may require elevated privileges.

mktemp -d

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT

Use a temporary-directory utility for unique temporary storage rather than inventing a name. Its options vary between GNU/Linux, macOS, and BSD.

Language-native APIs

Applications should normally use their language’s filesystem API instead of invoking a shell:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Python: pathlib.Path(...).mkdir(parents=True, exist_ok=True)
  • Node.js: fs.mkdir(..., { recursive: true })
  • Go: os.MkdirAll
  • C/POSIX: mkdir() or a higher-level filesystem abstraction

Quick reference

Goal Command Result
One directory mkdir project Creates project in the current directory.
Several directories mkdir src tests docs Attempts each operand in order.
Directory tree mkdir -p app/config/prod Creates missing components.
Private directory mkdir -m 700 secrets Requests owner-only access, subject to umask and ACLs.
Verbose creation mkdir -v -p a/b/c Prints implementation-specific creation messages.
Windows CMD mkdir C:WorkReports Creates the path under CMD command extensions.
PowerShell New-Item -ItemType Directory -Path .Reports Creates a directory and returns a DirectoryInfo object.

For standards and implementation details, see the POSIX mkdir utility specification, the GNU mkdir documentation, Linux mkdir(2), Windows mkdir documentation, and PowerShell’s New-Item documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.