Mkdir Explained
| mkdir |
| Developer: | Various open-source and commercial developers |
| 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 |
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
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.[10] Digital Research DR DOS 6.0[11] and Datalight ROM-DOS[12] also include an implementation of the and 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
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,[15] the default[16]), 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 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.
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/
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/"
This will create: tmpdir ________|______ | | |branches tags trunk | sources ____|_____ | | includes docs
See also
Further reading
- Book: Cooper. Jim. Special Edition Using MS-DOS 6.22, Third Edition. 2001. Que Publishing. 978-0789725738.
- Book: Kathy Ivens. Brian Proffit. 1993. OS/2 Inside & Out. Osborne McGraw-Hill. 978-0078818714.
- Book: Frisch, Æleen. 2001. Windows 2000 Commands Pocket Reference. O'Reilly. 978-0-596-00148-3.
- Book: Barrett, Daniel J.. 2012. Macintosh Terminal Pocket Guide: Take Command of Your Mac. O'Reilly. 978-1449328986.
External links
Notes and References
- Web site: Users guide . bitsavers.org . 2019-10-22 . 2019-09-25 . https://web.archive.org/web/20190925131719/http://bitsavers.org/pdf/digitalResearch/flexos/1073-2003_FlexOS_Users_Guide_V1.3_Nov86.pdf . dead .
- Web site: JaTomes Help - OS/2 Commands. www.jatomes.com. 2019-07-23. 2019-04-14. https://web.archive.org/web/20190414130029/http://www.jatomes.com/Help/Os2Cmd.php#MD. dead.
- Web site: GitHub - reactos/reactos: A free Windows-compatible Operating System. October 22, 2019. GitHub. July 23, 2019. December 11, 2017. https://web.archive.org/web/20171211170155/https://github.com/reactos/reactos. live.
- Web site: EFI Shells and Scripting . . 2013-09-25 . 2013-09-27 . https://web.archive.org/web/20130927203229/http://software.intel.com/en-us/articles/efi-shells-and-scripting/ . live .
- Web site: Reference manual . stratadoc.stratus.com . 2019-10-22 . 2019-09-22 . https://web.archive.org/web/20190922035829/https://stratadoc.stratus.com/vos/19.1.0/r098-19/wwhelp/wwhimpl/common/html/r098-19.pdf . live .
- Web site: Introduction to Tripos . 2019-10-22 . 2020-10-21 . https://web.archive.org/web/20201021043218/https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf . live .
- Book: AmigaDOS quick reference. Hannes. Rügheimer. Christian. Spanik. October 22, 1988. Grand Rapids, Mi : Abacus. 9781557550491. Internet Archive.
- Web site: Make new folder - MATLAB mkdir. www.mathworks.com. 2019-04-06. 2019-04-06. https://web.archive.org/web/20190406163934/https://www.mathworks.com/help/matlab/ref/mkdir.html. live.
- Web site: Function Reference: mkdir. octave.sourceforge.io.
- Book: Wolverton. Van. Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition. 2003. Microsoft Press. 0-7356-1812-7.
- Web site: DR DOS 6.0 User Guide Optimisation and Configuration Tips . 2019-08-13 . https://web.archive.org/web/20190930135943/http://www.4corn.co.uk/archive/docs/DR%20DOS%206.0%20User%20Guide-opt.pdf . 2019-09-30 . dead .
- Web site: Datalight ROM-DOS User's Guide. www.datalight.com. 2020-09-14. 2011-11-16. https://web.archive.org/web/20111116023237/http://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf. live.
- Web site: mkdir(1): make directories - Linux man page. linux.die.net. 2019-01-19. 2019-07-03. https://web.archive.org/web/20190703224521/https://linux.die.net/man/1/mkdir. live.
- Web site: Shell - KolibriOS wiki. wiki.kolibrios.org. 2019-08-11. 2019-02-11. https://web.archive.org/web/20190211231827/http://wiki.kolibrios.org/wiki/Shell. live.
- Web site: Microsoft Windows XP - Mkdir. Microsoft. https://web.archive.org/web/20160722020802/http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mkdir.mspx?mfr=true. July 22, 2016. 25 October 2012.
- Web site: Microsoft Windows XP - Cmd. Microsoft. 25 October 2012. 22 March 2016. https://web.archive.org/web/20160322205032/http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true. live.