mkdir

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.

mkdir
The mkdir command
Developer(s)Various open-source and commercial developers
Operating systemUnix, Unix-like, Plan 9, Inferno, DOS, MSX-DOS, FlexOS, OS/2, Windows, ReactOS, KolibriOS
TypeCommand
Licensecoreutils: GPLv3+
MS-DOS: MIT
ReactOS: GPLv1

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] DR DOS 6.0 also includes an implementation of the md and mkdir commands.[11]

The version of mkdir bundled in GNU coreutils was written by David MacKenzie.[12] It is also available in the open source MS-DOS emulator DOSBox and in KolibriOS.[13]

Usage

The ReactOS mkdir command

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,[14] the default[15]), 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 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, 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/{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
gollark: That makes you a BLASPH.
gollark: Ah. I see.
gollark: <@&198138780132179968> <@270035320894914560>/aus210 has stolen my (enchanted with Unbreaking something/Mending) elytra.I was in T79/i02p/n64c/pjals' base (aus210 wanted help with some code, and they live in the same place with some weird connecting tunnels) and came across an armor stand (it was in an area of the base I was trusted in - pjals sometimes wants to demo stuff to me or get me to help debug, and the claim organization is really odd). I accidentally gave it my neural connector, and while trying to figure out how to get it back swapped my armor onto it (turns out shiftrightclick does that). Eventually I got them both back, but while my elytra was on the stand aus210 stole it. I asked for it back and they repeatedly denied it.They have claimed:- they can keep it because I intentionally left it there (this is wrong, and I said so)- there was no evidence that it was mine so they can keep it (...)EDIT: valithor got involved and got them to actually give it back, which they did after ~10 minutes of generally delaying, apparently leaving it in storage, and dropping it wrong.
gollark: Someone had a problem with two mutually recursive functions (one was defined after the other), so I fixed that for them. Then I explained stack overflows and how that made their design (`mainScreen` calls `itemScreen` calls `mainScreen`...) problematic. Their suggested solution was to just capture the error and restart the program. Since they weren't entirely sure how to do *that*, their idea was to make it constantly ping their webserver and have another computer reboot it if it stopped.
gollark: potatOS is also secure <@!290217153293189120> ke

See also

References

  1. "Users guide" (PDF). bitsavers.org. Retrieved 2019-10-22.
  2. "JaTomes Help - OS/2 Commands". www.jatomes.com.
  3. "GitHub - reactos/reactos: A free Windows-compatible Operating System". October 22, 2019 via GitHub.
  4. "EFI Shells and Scripting". Intel. Retrieved 2013-09-25.
  5. "Reference manual" (PDF). stratadoc.stratus.com. Retrieved 2019-10-22.
  6. "Introduction to Tripos" (PDF). Retrieved 2019-10-22.
  7. Rügheimer, Hannes; Spanik, Christian (October 22, 1988). "AmigaDOS quick reference". Grand Rapids, Mi : Abacus via Internet Archive.
  8. "Make new folder - MATLAB mkdir". www.mathworks.com.
  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. ISBN 0-7356-1812-7.
  11. "DR DOS 6.0 User Guide Optimisation and Configuration Tips" (PDF). Archived from the original (PDF) on 2019-09-30. Retrieved 2019-08-13.
  12. "mkdir(1): make directories - Linux man page". linux.die.net.
  13. "Shell - KolibriOS wiki". wiki.kolibrios.org.
  14. "Microsoft Windows XP - Mkdir". Microsoft. Archived from the original on July 22, 2016. Retrieved 25 October 2012.
  15. "Microsoft Windows XP - Cmd". Microsoft. Retrieved 25 October 2012.

Further reading

  • 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.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.