| mkdir | |
|---|---|
The mkdir command | |
| Developers | Variousopen-source andcommercial developers |
| Operating system | Unix,Unix-like,Plan 9,Inferno,DOS,MSX-DOS,FlexOS,OS/2,Windows,ReactOS,KolibriOS |
| Platform | Cross-platform |
| Type | Command |
| License | GNUcoreutils:GPLv3+ MS-DOS, Plan 9:MIT FreeDOS:GPLv2+ ReactOS:GPLv2 |
Themkdir (makedirectory)command in theUnix,DOS,DRFlexOS,[1]IBMOS/2,[2]Microsoft Windows, andReactOS[3]operating systems is used to make a newdirectory. It is also available in theEFI shell[4] and in thePHPscripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated tomd.
The command is analogous to theStratusOpenVOScreate_dir command.[5]MetaComCoTRIPOS andAmigaDOS provide a similarMakeDir command to create new directories.[6][7] Thenumerical computing environmentsMATLAB andGNU Octave include anmkdir function with similar functionality.[8][9]
In early versions of Unix (4.1BSD and early versions ofSystem V), this command had to besetuidroot as thekernel did not have anmkdirsyscall. Instead, it made the directory withmknod and linked in the. and.. directory entries manually. The command is available inMS-DOS versions 2 and later.[10]Digital ResearchDR DOS 6.0[11] andDatalightROM-DOS[12] also include an implementation of themd andmkdir commands.
The version ofmkdir bundled inGNUcoreutils was written by David MacKenzie.[13]It is also available in theopen source MS-DOSemulatorDOSBox and inKolibriOS.[14]

mkdir commandNormal usage is as straightforward as follows:
mkdirname_of_directory
wherename_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,[15] the default[16]), multiple directories can be specified, andmkdir will try to create all of them.
On Unix-like operating systems,mkdir takes options. The options are:
-p (--parents):parents orpath, 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 theoctal permissions of directories created bymkdir .-p is most often used when usingmkdir 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 byshell scripts.
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 aShell extension, nothing mkdir does itself):
mkdir-ptmpdir/{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,docseval"mkdir -p tmpdir/{trunk/sources/{${DOMAIN_NAME}},branches,tags}"
This will create:
tmpdir ________|______ | | |branches tags trunk | sources ____|_____ | | includes docs
mkdir: make directories – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Groupmkdir(1) – Plan 9 Programmer's Manual, Volume 1mkdir(1) – Inferno General commandsManual