Mkdir

Directory creation command on various operating systems
title: "Mkdir" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["unix-sus2008-utilities", "plan-9-commands", "inferno-(operating-system)-commands", "internal-dos-commands", "msx-dos-commands", "os/2-commands", "reactos-commands", "windows-commands", "windows-administration", "ibm-i-qshell-commands"] description: "Directory creation command on various operating systems" topic_path: "technology/operating-systems" source: "https://en.wikipedia.org/wiki/Mkdir" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0
::summary Directory creation command on various operating systems ::
::data[format=table title="Infobox software"]
| Field | Value |
|---|---|
| name | mkdir |
| screenshot | Mkdir terminal.png |
| caption | The command |
| developer | Various open-source and commercial developers |
| operating system | Unix, Unix-like, Plan 9, Inferno, DOS, MSX-DOS, FlexOS, OS/2, Windows, ReactOS, KolibriOS |
| platform | Cross-platform |
| genre | Command |
| license | GNU coreutils: GPLv3+ |
| MS-DOS, Plan 9: MIT | |
| FreeDOS: GPLv2+ | |
| ReactOS: GPLv2 | |
| :: |
| name = mkdir
| logo =
| screenshot = Mkdir terminal.png
| screenshot size =
| caption = The command
| developer = Various open-source and commercial developers
| released =
| latest release version =
| latest release date =
| programming language =
| operating system = Unix, Unix-like, Plan 9, Inferno, DOS, MSX-DOS, FlexOS, OS/2, Windows, ReactOS, KolibriOS
| platform = Cross-platform
| genre = Command
| license = GNU coreutils: GPLv3+
MS-DOS, Plan 9: MIT
FreeDOS: GPLv2+
ReactOS: GPLv2
The mkdir (make directory) command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory. It is also available in the EFI shell{{cite web
| url = http://software.intel.com/en-us/articles/efi-shells-and-scripting/
| title = EFI Shells and Scripting
| publisher = Intel
| access-date = 2013-09-25
The command is analogous to the Stratus OpenVOS create_dir command. MetaComCo TRIPOS and AmigaDOS provide a similar MakeDir command to create new directories. The numerical computing environments MATLAB and GNU Octave include an mkdir
function with similar functionality.
History
In early versions of Unix (4.1BSD and early versions of System V), this command had to be setuid root as the kernel did not have an mkdir syscall. Instead, it made the directory with [mknod](mknod) and linked in the . and .. directory entries manually. The command is available in MS-DOS versions 2 and later. Digital Research DR DOS 6.0 and Datalight ROM-DOS also include an implementation of the and commands.
The version of mkdir bundled in GNU coreutils was written by David MacKenzie.
It is also available in the open source MS-DOS emulator DOSBox and in KolibriOS.
Usage
::figure[src="https://upload.wikimedia.org/wikipedia/commons/d/dc/ReactOS-0.4.13_mkdir_command_667x434.png" caption="The [[ReactOS]] mkdir command"]
::
Normal usage is as straightforward as follows:
::code[lang=bash] mkdir name_of_directory ::
where name_of_directory is the name of the directory one wants to create. When typed as above (i.e. normal usage), the new directory would be created within the current directory. On Unix and Windows (with Command extensions enabled, the default), multiple directories can be specified, and mkdir will try to create all of them.
Options
On Unix-like operating systems, mkdir takes options. The options are:
-p (--parents): parents or path, will also create all directories leading up to the given directory that do not exist already. For example,mkdir -p a/bwill create directoryaif it doesn't exist, then will create directorybinside directorya. If the given directory already exists, ignore the error.-m (--mode): mode, specify the octal permissions of directories created bymkdir.-pis most often used when usingmkdirto build up complex directory hierarchies, in case a necessary directory is missing or already there.-mis commonly used to lock down temporary directories used by shell scripts.
Examples
An example of -p in action is:
::code[lang=bash] mkdir -p /tmp/a/b/c ::
If /tmp/a exists but /tmp/a/b does not, mkdir will create /tmp/a/b before creating /tmp/a/b/c.
And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
::code[lang=bash] mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags} ::
If one is using variables with mkdir in a bash script, POSIX `special' built-in command 'eval' would serve its purpose.
::code[lang=bash] DOMAIN_NAME=includes,docs eval "mkdir -p tmpdir/{trunk/sources/{${DOMAIN_NAME}},branches,tags}" ::
This will create: ::code[lang=text] tmpdir _| | | | branches tags trunk | sources | | | includes docs ::
References
References
- "Users guide". bitsavers.org.
- "JaTomes Help - OS/2 Commands".
- (October 22, 2019). "GitHub - reactos/reactos: A free Windows-compatible Operating System".
- "Reference manual". stratadoc.stratus.com.
- "Introduction to Tripos".
- (October 22, 1988). "AmigaDOS quick reference". Grand Rapids, Mi : Abacus.
- "Make new folder - MATLAB mkdir".
- "Function Reference: mkdir".
- (2003). "Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition". [[Microsoft Press]].
- "DR DOS 6.0 User Guide Optimisation and Configuration Tips".
- "Datalight ROM-DOS User's Guide".
- "mkdir(1): make directories - Linux man page".
- "Shell - KolibriOS wiki".
- "Microsoft Windows XP - Mkdir". Microsoft.
- "Microsoft Windows XP - Cmd". Microsoft.
::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::