Mkdir
The mkdir (make directory) command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory.
≈ 9 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
The mkdir (make directory) command in the Unix, DOS, DR FlexOS,[1] IBM OS/2,[2] Microsoft Windows, and ReactOS[3] operating systems is used to make a new directory. It is also available in the EFI shell[4] 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.[5] MetaComCo TRIPOS and AmigaDOS provide a similar MakeDir command to create new directories.[6][7] The numerical computing environments MATLAB and GNU Octave include an mkdir
function with similar functionality.[8][9]
History
edit edit sourceIn 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.[10] Digital Research DR DOS 6.0[11] and Datalight ROM-DOS[12] also include an implementation of the md and mkdir commands.
The version of mkdir bundled in GNU coreutils was written by David MacKenzie.[13]
It is also available in the open source MS-DOS emulator DOSBox and in KolibriOS.[14]
Usage
edit edit sourceNormal usage is as straightforward as follows:
mkdir name_of_directorywhere 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,[15] the default[16]), multiple directories can be specified, and mkdir will try to create all of them.
Options
edit edit sourceOn 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/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 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
edit edit sourceAn example of -p in action is:
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 docsSee also
edit edit source- 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
edit edit source- ^ "Users guide" (PDF). bitsavers.org. Archived from the original (PDF) on 2019-09-25. Retrieved 2019-10-22. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "JaTomes Help - OS/2 Commands". www.jatomes.com. Archived from the original on 2019-04-14. Retrieved 2019-07-23. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "GitHub - reactos/reactos: A free Windows-compatible Operating System". October 22, 2019. Archived from the original on December 11, 2017. Retrieved July 23, 2019 – via GitHub. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "EFI Shells and Scripting". Intel. Archived from the original on 2013-09-27. Retrieved 2013-09-25. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Reference manual" (PDF). stratadoc.stratus.com. Archived (PDF) from the original on 2019-09-22. Retrieved 2019-10-22. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Introduction to Tripos" (PDF). Archived (PDF) from the original on 2020-10-21. Retrieved 2019-10-22. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ Rügheimer, Hannes; Spanik, Christian (October 22, 1988). AmigaDOS quick reference. Grand Rapids, Mi : Abacus. ISBN 9781557550491 – via Internet Archive. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Make new folder - MATLAB mkdir". www.mathworks.com. Archived from the original on 2019-04-06. Retrieved 2019-04-06. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Function Reference: mkdir". octave.sourceforge.io. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ Wolverton, Van (2003). Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition. Microsoft Press. ISBN 0-7356-1812-7. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "DR DOS 6.0 User Guide Optimisation and Configuration Tips" (PDF). Archived from the original (PDF) on 2019-09-30. Retrieved 2019-08-13. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Datalight ROM-DOS User's Guide" (PDF). www.datalight.com. Archived (PDF) from the original on 2011-11-16. Retrieved 2020-09-14. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "mkdir(1): make directories - Linux man page". linux.die.net. Archived from the original on 2019-07-03. Retrieved 2019-01-19. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Shell - KolibriOS wiki". wiki.kolibrios.org. Archived from the original on 2019-02-11. Retrieved 2019-08-11. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Microsoft Windows XP - Mkdir". Microsoft. Archived from the original on July 22, 2016. Retrieved 25 October 2012. Wikipedia revision 1352491760, retrieved 2026-11-19
- ^ "Microsoft Windows XP - Cmd". Microsoft. Archived from the original on 22 March 2016. Retrieved 25 October 2012. Wikipedia revision 1352491760, retrieved 2026-11-19
Further reading
edit edit source- Cooper, Jim (2001). Special Edition Using MS-DOS 6.22, Third Edition. Que Publishing. ISBN 978-0789725738.
- Kathy Ivens; Brian Proffit (1993). OS/2 Inside & Out. Osborne McGraw-Hill. ISBN 978-0078818714.
- Frisch, Æleen (2001). Windows 2000 Commands Pocket Reference. O'Reilly. ISBN 978-0-596-00148-3.
- Barrett, Daniel J. (2012). Macintosh Terminal Pocket Guide: Take Command of Your Mac. O'Reilly. ISBN 978-1449328986.
External links
edit edit source Wikibooks has a book on the topic of: Guide to Windows Commands The Wikibook Guide to Unix has a page on the topic of: Commands- Microsoft TechNet Mkdir article
mkdir: make directories – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Groupmkdir(1)– Plan 9 Programmer's Manual, Volume 1mkdir(1)– Inferno General commands Manual
- Categories
- List
Text derived from https://en.wikipedia.org/w/index.php?oldid=1352491760 under CC BY-SA 4.0; modifications have been made.