October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Linux mkdir: Create Directories, Build Paths, and Fix Common Errors

Use Linux mkdir to create one directory or a nested path, set target permissions, and understand existing-name, permission, quota, and path errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use mkdir DIR to create a directory in Linux, and mkdir -p PATH to create a nested path whose parent directories may not exist yet. Add -m MODE when you need to set the permissions of a directory named directly as a command-line target. The key distinction: -p accepts existing directories and creates missing parents, but it does not repair or change permissions on directories that already exist.

How do I create one or more directories in Linux?

Give mkdir one or more directory names. GNU Coreutils documents that “mkdir creates each directory name in the order given.” For example:

mkdir reports
mkdir reports 2026 drafts

The first command attempts to create reports. The second attempts to create three directories: reports, 2026, and drafts. Without -p, an existing destination is an error.

How do I create a nested directory path?

Use -p (parents) when one or more components of a path may be missing:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mkdir -p projects/site/assets

If projects or site does not exist, GNU mkdir creates the missing components needed for the target. If a component already exists as a directory, it is accepted and left in place, including its existing permission bits. This makes -p useful for setup commands that may be run repeatedly.

To see which directories GNU mkdir creates, use verbose mode:

mkdir -pv projects/site/assets

For scripts, use the command’s exit status to determine whether it succeeded: GNU mkdir returns zero on success and nonzero on failure.

Which mkdir option should I use?

Need Command pattern What it does
Create a new directory and treat an existing name as an error mkdir DIR Creates the named directory; an existing path produces an error.
Ensure a nested path exists mkdir -p PATH Creates missing parent components and accepts existing directories without changing their modes.
Set the mode of a directory named as a target mkdir -m MODE DIR Applies the requested mode to that command-line target; it does not set the modes of parents created with -p.

These option behaviors are documented for GNU Coreutils. Other implementations may differ; for portable scripts, consult the target system’s mkdir manual.

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

How do I set directory permissions with mkdir?

Use -m MODE to set the mode of directories specified directly as command-line targets:

mkdir -m 750 private

Mode 750 is only an example, not a universal recommendation. Choose permissions for the users and processes that need access, then check the result if the exact mode matters. GNU mkdir accepts chmod-style symbolic modes as well as numeric modes.

Why -m does not set permissions on -p-created parents

In GNU mkdir, -m applies to the named target directories; it does not control parent directories created along the way by -p. To control the mode bits of newly created parents, set umask before running the command. GNU documents this example:

(umask u=rwx,go=rx; mkdir -p P/Q)

The umask must include u=wx for this method to work. As a separate system-call rule, Linux documents that, absent a default ACL, a created directory’s mode is (mode & ~umask & 0777). System permission mechanisms can also affect the final result.

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

Group-shared directories

On most systems, GNU documentation says a directory with the set-group-ID bit causes new subfiles to inherit its group and new subdirectories to inherit that bit. The details can depend on the system and filesystem, so do not assume identical behavior everywhere.

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

Why does mkdir say “File exists” or “Permission denied”?

“File exists”

Plain mkdir DIR reports an error if the path already exists. With -p, an existing directory is acceptable, but an existing non-directory component cannot serve as a directory in the requested path. Linux’s mkdir(2) interface also documents EEXIST when the path already exists, including when the existing path is a symbolic link.

“Permission denied”

Creating a directory requires appropriate access along the path. Check that you have write permission on the directory that will contain the new directory, and search (x) permission on every directory component leading to it. Linux documents either a non-writable parent or a path component without search permission as causes of EACCES.

Quota exceeded or invalid path component

Linux documents EDQUOT when a user’s block or inode quota is exhausted. It also documents EINVAL for an invalid final component, with prohibited characters as an example. The exact message shown by a shell may vary, so use the reported error and the local mkdir manual when diagnosing a specific system.

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

Which mkdir behavior is portable?

The core task—creating directories—is widely available, but option details and extensions can vary between implementations. GNU-specific details in this guide, including its documented -m and parent-directory behavior, should not be assumed on every Unix-like system. Check man mkdir on the target machine when writing a portable script.

References: GNU Coreutils 9.11: mkdir invocation; Linux man-pages: mkdir(2); Linux man-pages: mkdir(1); GNU Coreutils: Directory Setuid and Setgid.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
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.