Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsUse 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:
#1 Best Overall
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.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
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.
Rank #4
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.
Best Value
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.
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.




