In the Windows Command Prompt, and in the Bash shell (including OS X & Ubuntu Terminal, Git Bash, etc.), the mkdir
command is used to create a new directory. In both shells, there are a few options supported; we’re only going to examine one of these in Bash, which corresponds to the default behavior in Command Prompt.
Commands
Windows Command Prompt
Syntax
mkdir {path}
The command creates the specified directory—including any necessary parent directories—on the specified drive. path
is interpreted in accordance with “Specifying file and directory paths”.
Note that md
is interchangeable with mkdir
in Windows Command Shell.
Example
mkdir ..\work\src
Creates a src
subdirectory in the work
subdirectory of the parent directory of the current directory. If the parent directory does not contain a work
subdirectory, one will be created automatically before the src
subdirectory is created.
Bash shell (including OS X & Ubuntu Terminal, Git Bash, etc.)
Syntax
mkdir [options] {path …}
This command creates one or more directories, as specified. path
is interpreted in accordance with “Specifying file and directory paths”.
The only option we’ll address at this time is --parents
, or the equivalent -p
(the latter is the form required in OS X). This option causes mkdir
to create any necessary parent directories (just as mkdir
in Windows Command Prompt does).
Example
mkdir --parents ../work/src ~/scratch
Creates 2 directories:
- A
src
subdirectory in thework
subdirectory of the parent directory of the current directory. If the parent directory does not contain awork
subdirectory, one will be created automatically before thesrc
subdirectory is created. - A
scratch
subdirectory in the current user’s home directory.
Tasks
-
In your command line program, use the
cd
command, with the appropriate command line arguments, to change the current working directory to theprojects
subdirectory of thebootcamp
directory you created in the environment preparation portion of the pre-work. -
Use the
mkdir
command to create the following subdirectories within theprojects
directory:test1
test2/test3
(Remember: In Windows Command Prompt, the forward slash should be replaced by a backslash.)