October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

mkdir -p in Linux: Create a Full Directory Path at Once

Run mkdir -p path/to/directory to create missing parent directories and accept an existing directory with GNU Coreutils.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create a directory and any missing parent directories in one command, run mkdir -p path/to/new/directory. With GNU Coreutils, the command also accepts a target that is already a directory, making it useful in repeatable setup commands.

What mkdir -p does

For example, mkdir -p project/logs/2026 creates the missing directories in that path, including project and logs if necessary. The path is relative to your current working directory. For an absolute path, start with a slash, as in mkdir -p /var/tmp/my-app/logs.

As an Amazon Associate I earn from qualifying purchases.

In GNU Coreutils 9.11, -p means that missing parent directories are created and an existing directory is accepted. The GNU manual says to “Ignore existing parent directories, and do not change their file permission bits.” GNU Coreutils: mkdir invocation

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

How it differs from plain mkdir

Command Missing parent directories Target already exists as a directory
mkdir path/to/new/directory Does not create them; the command fails if required parent directories are missing. GNU mkdir reports an error.
mkdir -p path/to/new/directory Creates missing parents as needed. Accepted without an error.

The -p option does not make an existing regular file usable as a directory. If a file occupies a path component that must be a directory, creation fails. Nor does the option grant permission to write in a protected location.

Control permissions on newly created directories

Do not assume that mkdir -p always creates directories with a fixed mode such as 755. Under GNU Coreutils, the permissions of new directories depend on the process’s umask. Existing parent directories are left unchanged.

To control permissions for newly created parent directories, set the umask before running mkdir. GNU’s manual gives this subshell example:

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

Using a subshell confines that umask change to the command group. The GNU manual also notes that -m sets permissions for directory names supplied directly on the command line; it does not set the permission bits of intermediate parents newly created by -p.

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

Show which directories were created

Add -v for a message about each directory created:

mkdir -pv project/logs/2026

GNU Coreutils documents an exit status of zero for success and nonzero for failure. Scripts can use that status to decide whether to continue.

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

Quick checks when the command fails

  • A parent path is a file: Check whether any required component already exists as a regular file; it cannot act as a directory.
  • You lack write permission: Check permissions on the parent location where the missing directory must be created. -p does not bypass them.
  • You expected exact permission bits: Check the active umask. For GNU mkdir, use umask to control newly created parents rather than relying on -m for those intermediate directories.

These behaviors are documented for GNU Coreutils 9.11. Linux systems can ship different implementations or versions, so consult the manual available on your system if its behavior differs.

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.