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.
#1 Best Overall
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.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsNames 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:
- 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.
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
-pwhen missing parents are expected. - Check the exit status; successful
mkdirreturns zero, failure returns nonzero. - Do not use
evalto assemble a command from input. - Do not hide diagnostics with
2>/dev/nullunless 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.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →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.
Rank #4
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.
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.
mkdir versus mkdir()
mkdir is a command-line utility. mkdir() is the POSIX/C interface:
Recommended Free Tools
Best Value
#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:
- 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.
Quick Recap
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.




