Themkdir(makedirectory)commandin theUnix,DOS,DRFlexOS,[1]IBMOS/2,[2]Microsoft Windows,andReactOS[3]operating systemsis 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.

mkdir
Developer(s)Variousopen-sourceandcommercialdevelopers
Written inPython 3
Operating systemUnix,Unix-like,Plan 9,Inferno,DOS,MSX-DOS,FlexOS,OS/2,Windows,ReactOS,KolibriOS
PlatformCross-platform
TypeCommand
LicenseGNUcoreutils:GPLv3+
MS-DOS,Plan 9:MIT
FreeDOS:GPLv2+
ReactOS:GPLv2

The command is analogous to theStratusOpenVOScreate_dircommand.[5]MetaComCoTRIPOSandAmigaDOSprovide a similarMakeDircommand to create new directories.[6][7]Thenumerical computingenvironmentsMATLABandGNU Octaveinclude anmkdir function with similar functionality.[8][9]

History

edit

In early versions of Unix (4.1BSDand early versions ofSystem V), this command had to besetuidrootas thekerneldid not have anmkdirsyscall.Instead, it made the directory withmknodand linked in the.and..directory entries manually. The command is available inMS-DOSversions 2 and later.[10]Digital ResearchDR DOS 6.0[11]andDatalightROM-DOS[12]also include an implementation of themdandmkdircommands.

The version ofmkdirbundled inGNUcoreutilswas written by David MacKenzie.[13] It is also available in theopen sourceMS-DOSemulatorDOSBoxand inKolibriOS.[14]

Usage

edit
TheReactOSmkdircommand

Normal usage is as straightforward as follows:

mkdirname_of_directory

wherename_of_directoryis 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, andmkdirwill try to create all of them.

Options

edit

On Unix-like operating systems,mkdirtakes options. The options are:

  • -p (--parents):parentsorpath,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 theoctal permissionsof 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 byshell scripts.

Examples

edit

An example of-pin action is:

mkdir-p/tmp/a/b/c

If/tmp/aexists but/tmp/a/bdoes not,mkdirwill create/tmp/a/bbefore creating/tmp/a/b/c.

And an even more powerful command, creating a full tree at once (this however is aShellextension, 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,docs
eval"mkdir -p tmpdir/{trunk/sources/{${DOMAIN_NAME}},branches,tags} "

This will create:

tmpdir
________|______
| | |
branches tags trunk
|
sources
____|_____
| |
includes docs

See also

edit

References

edit
  1. ^"Users guide"(PDF).bitsavers.org. Archived fromthe original(PDF)on 2019-09-25.Retrieved2019-10-22.
  2. ^"JaTomes Help - OS/2 Commands".jatomes.
  3. ^"GitHub - reactos/reactos: A free Windows-compatible Operating System".October 22, 2019 – via GitHub.
  4. ^"EFI Shells and Scripting".Intel.Retrieved2013-09-25.
  5. ^"Reference manual"(PDF).stratadoc.stratus.Retrieved2019-10-22.
  6. ^"Introduction to Tripos"(PDF).Retrieved2019-10-22.
  7. ^Rügheimer, Hannes; Spanik, Christian (October 22, 1988).AmigaDOS quick reference.Grand Rapids, Mi: Abacus.ISBN9781557550491– via Internet Archive.
  8. ^"Make new folder - MATLAB mkdir".mathworks.
  9. ^"Function Reference: mkdir".octave.sourceforge.io.
  10. ^Wolverton, Van (2003).Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition.Microsoft Press.ISBN0-7356-1812-7.
  11. ^"DR DOS 6.0 User Guide Optimisation and Configuration Tips"(PDF).Archived fromthe original(PDF)on 2019-09-30.Retrieved2019-08-13.
  12. ^"Datalight ROM-DOS User's Guide"(PDF).datalight.
  13. ^"mkdir(1): make directories - Linux man page".linux.die.net.
  14. ^"Shell - KolibriOS wiki".wiki.kolibrios.org.
  15. ^"Microsoft Windows XP - Mkdir".Microsoft. Archived fromthe originalon July 22, 2016.Retrieved25 October2012.
  16. ^"Microsoft Windows XP - Cmd".Microsoft.Retrieved25 October2012.

Further reading

edit
edit