{{Short description|Directory creation command on various operating systems}} {{Lowercase title}} {{Infobox software | name = mkdir | logo = | screenshot = Mkdir terminal.png | screenshot size = | caption = The {{code|mkdir}} 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+<br />MS-DOS, Plan 9: MIT<br />FreeDOS: GPLv2+<br />ReactOS: GPLv2 }} The '''<code>mkdir</code>''' ('''m'''a'''k'''e '''dir'''ectory) command in the Unix, DOS, DR FlexOS,<ref>{{cite web |url=http://www.bitsavers.org/pdf/digitalResearch/flexos/1073-2003_FlexOS_Users_Guide_V1.3_Nov86.pdf |title=Users guide |publisher=bitsavers.org |access-date=2019-10-22 |archive-date=2019-09-25 |archive-url=https://web.archive.org/web/20190925131719/http://bitsavers.org/pdf/digitalResearch/flexos/1073-2003_FlexOS_Users_Guide_V1.3_Nov86.pdf |url-status=dead }}</ref> IBM OS/2,<ref>{{cite web|url=http://www.jatomes.com/Help/Os2Cmd.php#MD|title=JaTomes Help - OS/2 Commands|website=www.jatomes.com|access-date=2019-07-23|archive-date=2019-04-14|archive-url=https://web.archive.org/web/20190414130029/http://www.jatomes.com/Help/Os2Cmd.php#MD|url-status=dead}}</ref> Microsoft Windows, and ReactOS<ref>{{cite web|url=https://github.com/reactos/reactos|title=GitHub - reactos/reactos: A free Windows-compatible Operating System|date=October 22, 2019|via=GitHub|access-date=July 23, 2019|archive-date=December 11, 2017|archive-url=https://web.archive.org/web/20171211170155/https://github.com/reactos/reactos|url-status=live}}</ref> operating systems is used to make a new directory. It is also available in the EFI shell<ref name="EFI-Shells-and-Scripting">{{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 | archive-date = 2013-09-27 | archive-url = https://web.archive.org/web/20130927203229/http://software.intel.com/en-us/articles/efi-shells-and-scripting/ | url-status = live }}</ref> and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to <code>'''md'''</code>.
The command is analogous to the Stratus OpenVOS <code>create_dir</code> command.<ref>{{cite web |url=http://stratadoc.stratus.com/vos/19.1.0/r098-19/wwhelp/wwhimpl/common/html/r098-19.pdf |title=Reference manual |publisher=stratadoc.stratus.com |access-date=2019-10-22 |archive-date=2019-09-22 |archive-url=https://web.archive.org/web/20190922035829/https://stratadoc.stratus.com/vos/19.1.0/r098-19/wwhelp/wwhimpl/common/html/r098-19.pdf |url-status=live }}</ref> MetaComCo TRIPOS and AmigaDOS provide a similar <code>MakeDir</code> command to create new directories.<ref>{{cite web |url=https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf |title=Introduction to Tripos |access-date=2019-10-22 |archive-date=2020-10-21 |archive-url=https://web.archive.org/web/20201021043218/https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf |url-status=live }}</ref><ref>{{cite book|url=http://archive.org/details/1988-rugheimer-spanik-amigados-quick-reference|title=AmigaDOS quick reference|first1=Hannes|last1=Rügheimer|first2=Christian|last2=Spanik|date=October 22, 1988|publisher=Grand Rapids, Mi : Abacus|isbn=9781557550491|via=Internet Archive}}</ref> The numerical computing environments MATLAB and GNU Octave include an <code>mkdir</code> function with similar functionality.<ref>{{cite web|url=https://www.mathworks.com/help/matlab/ref/mkdir.html|title=Make new folder - MATLAB mkdir|website=www.mathworks.com|access-date=2019-04-06|archive-date=2019-04-06|archive-url=https://web.archive.org/web/20190406163934/https://www.mathworks.com/help/matlab/ref/mkdir.html|url-status=live}}</ref><ref>{{cite web|url=https://octave.sourceforge.io/octave/function/mkdir.html|title=Function Reference: mkdir|website=octave.sourceforge.io}}</ref>
==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 <code>mkdir</code> syscall. Instead, it made the directory with <code>mknod</code> and linked in the <code>.</code> and <code>..</code> directory entries manually. The command is available in MS-DOS versions 2 and later.<ref name="RUNNINGMSDOS">{{Cite book|author-last=Wolverton|author-first=Van|title=Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition|date=2003|publisher=Microsoft Press|isbn=0-7356-1812-7}}</ref> Digital Research DR DOS 6.0<ref name="drdos6userguide">{{Cite web |url=https://www.4corn.co.uk/archive/docs/DR%20DOS%206.0%20User%20Guide-opt.pdf |title=DR DOS 6.0 User Guide Optimisation and Configuration Tips |access-date=2019-08-13 |archive-url=https://web.archive.org/web/20190930135943/http://www.4corn.co.uk/archive/docs/DR%20DOS%206.0%20User%20Guide-opt.pdf |archive-date=2019-09-30 |url-status=dead }}</ref> and Datalight ROM-DOS<ref>{{Cite web|url=https://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf|title=Datalight ROM-DOS User's Guide|website=www.datalight.com|access-date=2020-09-14|archive-date=2011-11-16|archive-url=https://web.archive.org/web/20111116023237/http://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf|url-status=live}}</ref> also include an implementation of the {{code|md}} and {{code|mkdir}} commands.
The version of <code>mkdir</code> bundled in GNU coreutils was written by David MacKenzie.<ref>{{cite web|url=https://linux.die.net/man/1/mkdir|title=mkdir(1): make directories - Linux man page|website=linux.die.net|access-date=2019-01-19|archive-date=2019-07-03|archive-url=https://web.archive.org/web/20190703224521/https://linux.die.net/man/1/mkdir|url-status=live}}</ref> It is also available in the open source MS-DOS emulator DOSBox and in KolibriOS.<ref>{{cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org|access-date=2019-08-11|archive-date=2019-02-11|archive-url=https://web.archive.org/web/20190211231827/http://wiki.kolibrios.org/wiki/Shell|url-status=live}}</ref>
==Usage== [[File:ReactOS-0.4.13 mkdir command 667x434.png|thumb|300px|The ReactOS <code>mkdir</code> command]] Normal usage is as straightforward as follows:
<syntaxhighlight lang="bash"> mkdir name_of_directory </syntaxhighlight>
where <code>name_of_directory</code> 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,<ref>{{cite web|url=http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mkdir.mspx?mfr=true|title=Microsoft Windows XP - Mkdir|publisher=Microsoft|archive-url=https://web.archive.org/web/20160722020802/http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mkdir.mspx?mfr=true|archive-date=July 22, 2016|access-date=25 October 2012}}</ref> the default<ref>{{cite web|title=Microsoft Windows XP - Cmd|url=http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true|publisher=Microsoft|access-date=25 October 2012|archive-date=22 March 2016|archive-url=https://web.archive.org/web/20160322205032/http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true|url-status=live}}</ref>), multiple directories can be specified, and <code>mkdir</code> will try to create all of them.
===Options=== On Unix-like operating systems, <code>mkdir</code> takes options. The options are: * <code>-p (--parents)</code>: ''parents'' or ''path'', will also create all directories leading up to the given directory that do not exist already. For example, <code>mkdir -p a/b</code> will create directory <code>a</code> if it doesn't exist, then will create directory <code>b</code> inside directory <code>a</code>. If the given directory already exists, ignore the error. * <code>-m (--mode)</code>: ''mode'', specify the octal permissions of directories created by <code>mkdir</code> . <code>-p</code> is most often used when using <code>mkdir</code> to build up complex directory hierarchies, in case a necessary directory is missing or already there. <code>-m</code> is commonly used to lock down temporary directories used by shell scripts.
===Examples=== An example of <code>-p</code> in action is:
<syntaxhighlight lang="bash"> mkdir -p /tmp/a/b/c </syntaxhighlight>
If <code>/tmp/a</code> exists but <code>/tmp/a/b</code> does not, <code>mkdir</code> will create <code>/tmp/a/b</code> before creating <code>/tmp/a/b/c</code>.
And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
<syntaxhighlight lang="bash"> mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags} </syntaxhighlight>
If one is using variables with mkdir in a bash script, POSIX `special' built-in command 'eval' would serve its purpose.
<syntaxhighlight lang="bash"> DOMAIN_NAME=includes,docs eval "mkdir -p tmpdir/{trunk/sources/{${DOMAIN_NAME}},branches,tags}" </syntaxhighlight>
This will create: <syntaxhighlight lang="text"> tmpdir ________|______ | | | branches tags trunk | sources ____|_____ | | includes docs </syntaxhighlight>
==See also== * Filesystem Hierarchy Standard * GNU Core Utilities * Find – The find command coupled with mkdir can be used to only recreate a directory structure (without files). * List of Unix commands * List of DOS commands
==References== {{Reflist}}
==Further reading== *{{Cite book|author-last=Cooper|author-first=Jim|title=Special Edition Using MS-DOS 6.22, Third Edition|date=2001|publisher=Que Publishing|isbn=978-0789725738}} *{{Cite book|author1=Kathy Ivens|author2=Brian Proffit|year=1993|title=OS/2 Inside & Out|publisher=Osborne McGraw-Hill|isbn=978-0078818714}} *{{Cite book|first=Æleen|last=Frisch|year=2001|title=Windows 2000 Commands Pocket Reference|publisher=O'Reilly|isbn=978-0-596-00148-3}} *{{Cite book|first=Daniel J.|last=Barrett|year=2012|title=Macintosh Terminal Pocket Guide: Take Command of Your Mac|publisher=O'Reilly|isbn=978-1449328986}}
==External links== {{Wikibooks|Guide to Windows Commands}} {{Wikibooks|Guide to Unix|Commands}} * [https://technet.microsoft.com/en-us/library/bb490930.aspx Microsoft TechNet Mkdir article] * {{man|cu|mkdir|SUS|make directories}} * {{man|1|mkdir|Plan 9}} * {{man|1|mkdir|Inferno}}
{{Unix commands}} {{Plan 9 commands}} {{Core Utilities commands}} {{Windows commands}}
Category:Unix SUS2008 utilities Category:Plan 9 commands Category:Inferno (operating system) commands Category:Internal DOS commands Category:MSX-DOS commands Category:OS/2 commands Category:ReactOS commands Category:Windows commands Category:Windows administration Category:IBM i Qshell commands