mkdir
{{Short description|Directory creation command on various operating systems}}
{{Lowercase|title=mkdir}}
{{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 = python3
| 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
}}
(make directory) command in the Unix, DOS, DR FlexOS,{{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 }} IBM OS/2,{{cite web|url=http://www.jatomes.com/Help/Os2Cmd.php#MD|title=JaTomes Help - OS/2 Commands|website=www.jatomes.com}} Microsoft Windows, and ReactOS{{cite web|url=https://github.com/reactos/reactos|title=GitHub - reactos/reactos: A free Windows-compatible Operating System|date=October 22, 2019|via=GitHub}} 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
}} and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to md
.
The command is analogous to the Stratus OpenVOS create_dir
command.{{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}} MetaComCo TRIPOS and AmigaDOS provide a similar MakeDir
command to create new directories.{{cite web|url=https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf |title=Introduction to Tripos |access-date=2019-10-22}}{{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}} The numerical computing environments MATLAB and GNU Octave include an mkdir
function with similar functionality.{{cite web|url=https://www.mathworks.com/help/matlab/ref/mkdir.html|title=Make new folder - MATLAB mkdir|website=www.mathworks.com}}{{cite web|url=https://octave.sourceforge.io/octave/function/mkdir.html|title=Function Reference: mkdir|website=octave.sourceforge.io}}
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
and linked in the .
and ..
directory entries manually. The command is available in MS-DOS versions 2 and later.{{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}} Digital Research DR DOS 6.0{{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 }} and Datalight ROM-DOS{{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}} also include an implementation of the {{code|md}} and {{code|mkdir}} commands.
The version of mkdir
bundled in GNU coreutils was written by David MacKenzie.{{cite web|url=https://linux.die.net/man/1/mkdir|title=mkdir(1): make directories - Linux man page|website=linux.die.net}}
It is also available in the open source MS-DOS emulator DOSBox and in KolibriOS.{{cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org}}
Usage
File:ReactOS-0.4.13 mkdir command 667x434.png mkdir
command]]
Normal usage is as straightforward as follows:
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,{{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}} the default{{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}}), 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/b
will create directorya
if it doesn't exist, then will create directoryb
inside directorya
. If the given directory already exists, ignore the error.-m (--mode)
: mode, specify the octal permissions of directories created bymkdir
.
-p
is most often used when using mkdir
to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m
is commonly used to lock down temporary directories used by shell scripts.
=Examples=
An example of -p
in action is:
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):
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.
DOMAIN_NAME=includes,docs
eval "mkdir -p tmpdir/{trunk/sources/{${DOMAIN_NAME}},branches,tags}"
This will create:
tmpdir
________|______
| | |
branches tags trunk
|
sources
____|_____
| |
includes docs
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:Inferno (operating system) commands
Category:Internal DOS commands