iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use mkdir -p path/to/new/directory to create a directory and any missing parent directories in one command. With GNU Coreutils, the command also accepts an existing directory without treating it as an error.
How to create a directory path with mkdir -p
For example, this command creates project, logs, and 2026 as needed:
mkdir -p project/logs/2026
The path is relative to your current working directory. To request a location from the filesystem root, begin with a slash, such as /var/tmp/my-app/logs. GNU Coreutils 9.11 documents -p as creating missing parent directories and accepting an existing requested directory. See the GNU Coreutils mkdir invocation reference.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →What happens if part of the path already exists?
With GNU mkdir -p, existing directories in the path are left in place; their permission bits are not changed. This makes the command useful in repeatable setup scripts, where a directory may already have been created by an earlier run.
#1 Best Overall
Without -p, GNU mkdir reports an error if the requested directory name already exists. The option does not make an existing regular file usable as a directory: if a file occupies a required path component, creation cannot proceed through it.
How permissions work for directories created by -p
Do not assume every new directory will have a fixed mode such as 755. For GNU Coreutils, the permissions of newly created directories are affected by the process’s umask. If parent-directory permissions need to be controlled, GNU recommends setting the umask before running mkdir. For example, this subshell applies a mask for this command without changing the calling shell’s umask:
(umask u=rwx,go=rx; mkdir -p P/Q)
The -m option does not set the permission bits of intermediate parent directories that -p creates; GNU documents it as applying to directory names given directly on the command line. Avoid relying on -m to control every newly created component of a nested path.
How to see what was created and check for errors
Add -v to print a message for each directory GNU mkdir creates:
mkdir -pv project/logs/2026
GNU documents an exit status of zero for success and nonzero for failure, so scripts can check whether the command succeeded rather than assuming that a requested path was created.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.When mkdir -p is not enough
- A path component is a regular file: the command cannot use that file as a parent directory. Choose a different path or resolve the conflicting file deliberately.
- You lack permission to create a directory:
-pdoes not grant write permission or bypass protections on the relevant parent directories. - You need specific permissions on new directories: account for the active
umask; for nested paths, remember that GNU-mdoes not set the modes of intermediate parents created by-p.
These behaviors are documented for GNU Coreutils 9.11. Linux systems may provide different mkdir implementations or versions, so check the local manual if exact implementation-specific behavior matters.
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.
Free tools Windows power users keep installed
One-click scans. No signup required.

