Template:Short description Template:Lowercase {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other (make directory) command in the Unix, DOS, DR FlexOS,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> IBM OS/2,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Microsoft Windows, and ReactOS<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> operating systems is used to make a new directory. It is also available in the EFI shell<ref name="EFI-Shells-and-Scripting">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> 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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> MetaComCo TRIPOS and AmigaDOS provide a similar MakeDir command to create new directories.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>Template:Cite book</ref> The numerical computing environments MATLAB and GNU Octave include an mkdir function with similar functionality.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

HistoryEdit

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.<ref name="RUNNINGMSDOS">Template:Cite book</ref> Digital Research DR DOS 6.0<ref name="drdos6userguide">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> and Datalight ROM-DOS<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> also include an implementation of the <syntaxhighlight lang="text" class="" style="" inline="1">md</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">mkdir</syntaxhighlight> commands.

The version of mkdir bundled in GNU coreutils was written by David MacKenzie.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> It is also available in the open source MS-DOS emulator DOSBox and in KolibriOS.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

UsageEdit

Normal usage is as straightforward as follows:

<syntaxhighlight lang="bash"> mkdir name_of_directory </syntaxhighlight>

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,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> the default<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>), multiple directories can be specified, and mkdir will try to create all of them.

OptionsEdit

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 directory a if it doesn't exist, then will create directory b inside directory a. If the given directory already exists, ignore the error.
  • -m (--mode): mode, specify the octal permissions of directories created by mkdir .

-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.

ExamplesEdit

An example of -p in action is:

<syntaxhighlight lang="bash"> mkdir -p /tmp/a/b/c </syntaxhighlight>

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):

<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 alsoEdit

ReferencesEdit

Template:Reflist

Further readingEdit

External linksEdit

Template:Sister project Template:Sister project

Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands Template:Windows commands