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
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.
#1 Best Overall
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.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →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.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.
-pdoes not bypass them. - You expected exact permission bits: Check the active
umask. For GNUmkdir, useumaskto control newly created parents rather than relying on-mfor 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.
Quick Recap
Best Value
Rank #4
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.




